I am using SQL Server 2008. I know if a table has no clustered index, then it is called heap, or else the storage model is called clustered index (B-Tree).
I want to learn more about what exactly means heap storage, what it looks like and whether it is organized as "heap" data structure (e.g. minimal heap, maximum heap). Any recommended readings? I want to more a bit more internals, but not too deep. :-)
thanks in advance, George
Heap storage has nothing to do with these heaps.
Heap just means records themselves are not ordered (i. e. not linked to one another).
When you insert a record, it just gets inserted into the free space the database finds.
Updating a row in a heap based table does not affect other records (though it affects secondary indexes)
If you create a secondary index on a
HEAPtable, theRID(a kind of a physical pointer to the storage space) is used as a row pointer.Clustered index means that the records are part of a
B-Tree. When you insert a record, theB-Treeneeds to be relinked.Updating a row in a clustered table causes relinking of the B-Tree, i. e. updating internal pointers in other records.
If you create a secondary index on a clustered table, the value of the clustered index key is used as a row pointer.
This means a clustered index should be unique. If a clustered index is not unique, a special hidden column called
uniquifieris appended to the index key that makes if unique (and larger in size).It is also worth noting that creating a secondary index on a column makes the values or the clustered index's key to be the part of the secondayry index's key.
By creating an index on a clustered table, you in fact always get a composite index
Index
IX_mytable_5678is in fact an index on the following columns:This has one more side effect:
A
DESCcondition in a single-column index on a clustered table makes sense inSQL ServerThis index:
can be used in a query like this:
, while this one:
can be used in a query like this: