Download pptx - Indexing basics

Transcript
Page 1: Indexing basics

IndexingLet’s rediscover the Basics

Page 2: Indexing basics

Introduction

• Sourabh Agarwal

• Premier Field Engineer – Microsoft Services

• Blogs: www.sqluninterrupted.com

• Facebook: www.facebook.com\troubleshootingsql, www.facebook.com\sqlserverfaq

• Twitter: @napsterreturns

Page 3: Indexing basics

Base Table

• Heap Or Clustered Index

• If Heap, Managed by the IAM

• If Clustered managed as a Balanced Tree.

Page 4: Indexing basics

HEAP

• Random (Non Sequential) collection of Pages

• Managed through the IAM (Index Allocation Map)

Page 5: Indexing basics

Clustered Indexes

• Balanced Tree Structure

• Index Pages on Root and Intermediate Pages

• Actual Data Pages as leaf Pages

• ** IAM page is still maintained

Page 6: Indexing basics

DEMO

• HEAP Table Structure

• Clustered Index Structure

Page 7: Indexing basics

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.

Page 8: Indexing basics

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

Page 9: Indexing basics

Non-Clustered Index On Clustered Index Table

• Index Key Values on the Root and Intermediate levels.

• Non-Clustered Index Key + Clustered Index Key Value

Page 10: Indexing basics

DEMO

• Non-Clustered Indexes on Heap

• Non-Clustered Indexes on Clustered Index Tables

• Non-Clustered Indexes with include Columns.

Page 11: Indexing basics

Recommended