Most of this post is about a collection from MSDN.
SQL Server uses B+ tree to create index. That means it can be not balanced.
In a B-Tree index, each page contains pointers pointing to previous page and next page in the same index level. In SQL Server, it has 96 bytes for the header. This is same in both index page and data page. In the data part of the index page, each index row points to page in next level towards to leaf.
Another type of index is bitmap index, which is not supported in SQL Server. It's designed for rows with lot of duplicate and good for analytic processes. Its overhead on DML is heavier than B-Tree index.
Table:
A table is contained in one or more partitions and each partition contains data rows in either a heap or a clustered index structure. The pages of the heap or clustered index are managed in one or more allocation units, depending on the column types in the data rows.
A partition is a user-defined unit of data organization. When a table or index uses multiple partitions, the data is partitioned
horizontally so that groups of rows are mapped into individual
partitions, based on a specified column. The partitions can be put on
one or more filegroups in the database.
To view the partitions used by a table or index, use the sys.partitions (Transact-SQL) catalog view.
Allocation Unit:
IN_ROW_DATA, ROW_OVERFLOW_DATA, LOB_DATA
HEAP: a table without a clustered index
index_id=0 in sys.partitions.
The data rows are not stored in any particular order, and there is no
particular order to the sequence of the data pages. The data pages are
not linked in a linked list
The column first_iam_page in the sys.system_internals_allocation_units system view points to the first IAM page in the chain of IAM(Index Allocation Map) pages that manage the space allocated to the heap in a specific partition. SQL Server uses the IAM pages to move through the heap. The data pages and the rows within them are not in any specific order and are not linked. The only logical connection between data pages is the information recorded in the IAM pages.
Clustered Index Structure:
index_id=1 in sys.partitions table
Non-Clustered index Structure:
index_id>1 in sys.partitions
Each index row contains the nonclustered key value, a row locator (RID or Clustered index Keys) and any included, or nonkey, columns.
Quick tips or notes that probably reflects 20 percent of knowledge that usually does 80 percent of job.
Showing posts with label index structure. Show all posts
Showing posts with label index structure. Show all posts
Monday, November 19, 2012
Friday, November 16, 2012
Duplicate Index
A index is duplicated if its tree structure and usage are the same as another one on the same table.
sp-helpindex can't tell you if indexes are really the same on tree structure and usage.
(
Clustered index is the data.
Non-clustered index is duplicated data. These duplicated data helps SQL Server efficiently find the real data.
)
Non-Clustered index Structure:
. Key
. A leaf level entry(actual data stored in index+lookup values+included columns)
Here lookup values are either clustered index key if table has clustered index or RID if table is a heap. It's used to look for actual data row.
A RID is an 8-byte structure consisting of 2:4:2 bytes which breakdown into 2 for the FileID, 4 for the PageID and 2 for the slot number.
For non-unique non-clustered index, clustered keys are stored in both its tree and leaf nodes.
For unique non-clustered index, clustered key are stored only in its leaf nodes.
(A nonunique nonclustered needs to have the lookup value pushed up into the tree (for navigation). A unique nonclustered index does not.)
Sequence of included columns does not matter on usage of index so that difference on the sequence will be ignored.
Credit to Kimberly. Understanding Duplicate Indexes
sp-helpindex can't tell you if indexes are really the same on tree structure and usage.
(
Clustered index is the data.
Non-clustered index is duplicated data. These duplicated data helps SQL Server efficiently find the real data.
)
Non-Clustered index Structure:
. Key
. A leaf level entry(actual data stored in index+lookup values+included columns)
Here lookup values are either clustered index key if table has clustered index or RID if table is a heap. It's used to look for actual data row.
A RID is an 8-byte structure consisting of 2:4:2 bytes which breakdown into 2 for the FileID, 4 for the PageID and 2 for the slot number.
For non-unique non-clustered index, clustered keys are stored in both its tree and leaf nodes.
For unique non-clustered index, clustered key are stored only in its leaf nodes.
(A nonunique nonclustered needs to have the lookup value pushed up into the tree (for navigation). A unique nonclustered index does not.)
Sequence of included columns does not matter on usage of index so that difference on the sequence will be ignored.
Credit to Kimberly. Understanding Duplicate Indexes
unique nonclustered needs to have the lookup value pushed up into
the tree (for navigation). A unique nonclustered index does not.
Read more: http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx#ixzz2CN0
Read more: http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx#ixzz2CN0
A RID is an 8-byte structure consisting of 2:4:2 bytes which breakdown
into 2 for the FileID, 4 for the PageID and 2 for the slot number
Read more: http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx#ixzz2CMy4WPR5
Read more: http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx#ixzz2CMy4WPR5
A RID is an 8-byte structure consisting of 2:4:2 bytes which breakdown
into 2 for the FileID, 4 for the PageID and 2 for the slot number.
Read more: http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx#ixzz2CMxou9p6
Read more: http://sqlskills.com/BLOGS/KIMBERLY/post/UnderstandingDuplicateIndexes.aspx#ixzz2CMxou9p6
Subscribe to:
Posts (Atom)



