Sql-server – Index: Does 0% fragmentation imply a B-tree

indexsql server

I am currently dealing with Microsoft SQL Server and its index structures. The data structures for this are trees.

When I reorganize a table index (e.g. the primary key), the result afterwards is 0% fragmentation. Then, in my opinion, the tree is optimally set up. Does this also mean that the structure is now a B-tree, i.e. is a fully balanced tree?

Best Answer

The "B" in B-tree doesn't necessarily stand for "balanced". It depends on who you ask. See for instance this. As often is the case, terminology degrades (over time).

All SQL Server "row indexes" (as opposed to other types of indexes in SQL Server like hash, columnstore, full-text, XML (to some extent) and geospatial) are B-tree indexes. They are always "balanced" in the sense that you have the same depth (number of pages) from the root to all leaf pages.

This has no relationship with any of the two types of fragmentation that we usually talk about in the SQL Server world: external (jump back and forth when following the linked list) or internal (non-full pages).

One can argue that a clustered index in SQL Server should be considered a B+ tree, since the leaf "has the data", but again I doubt that you will find and authoritative reference for how the terms are used.