IndexingLet’s rediscover the Basics
Introduction
• Sourabh Agarwal
• Premier Field Engineer – Microsoft Services
• Blogs: www.sqluninterrupted.com
• Facebook: www.facebook.com\troubleshootingsql, www.facebook.com\sqlserverfaq
• Twitter: @napsterreturns
Base Table
• Heap Or Clustered Index
• If Heap, Managed by the IAM
• If Clustered managed as a Balanced Tree.
HEAP
• Random (Non Sequential) collection of Pages
• Managed through the IAM (Index Allocation Map)
Clustered Indexes
• Balanced Tree Structure
• Index Pages on Root and Intermediate Pages
• Actual Data Pages as leaf Pages
• ** IAM page is still maintained
DEMO
• HEAP Table Structure
• Clustered Index Structure
Non-Clustered Indexes
• Created On Top of the base Tables
• Separate Structures, occupies space in the SQL Data File
• Can be • Unique Non Clustered Indexes
• Non-Unique Non Clustered Indexes
• Single Columns/Multi Columns
• INCLUDE can be used to store other column values in the index.
Non-Clustered Index on HEAP
• Index Keys on Root or Intermediate Pages
• Index Keys + Row ID in the Leaf Pages....
........
........
........
........
........
....
....
........
........
........
....
Non-leafLevel
LeafLevel
Non-clusteredIndex Pages
DataPages
Non-Clustered Index On Clustered Index Table
• Index Key Values on the Root and Intermediate levels.
• Non-Clustered Index Key + Clustered Index Key Value
DEMO
• Non-Clustered Indexes on Heap
• Non-Clustered Indexes on Clustered Index Tables
• Non-Clustered Indexes with include Columns.