Download presentation
Presentation is loading. Please wait.
1
Indexes: The Basics Kathi Kellenberger
3
Good things come in small packages…
4
Heaps B-Trees Two Types of Tables
Heaps – not logically organized. Table without a clustered index B-Trees – used for clustered indexes and non-clustered indexes Data is organized by the key Heaps B-Trees
5
Heap M S D X A T F When looking for a value within a heap, have to scan the data to find it. If I am looking for A, I have to look at M, S, D, X to get to A No organization Good in some circumstances like loading staging tables
6
B-Tree M T D A F S X Balanced tree Hierarchy
When I want to find a value, just have travel down the levels To find A, I start at M, is A less than M? Go to D. Is A Less than D? Go to A. When you add a clustered index to a table, it is organized as a B Tree A F S X
7
Find the Number Game How long to find a number when the numbers are random? How long when they are organized in a b-tree structure?
8
Clustered Index Structure
M D T Non-Leaf Levels A F S X A D F Leaf Level M S T X Non-leaf levels contain the cluster key Leaf levels contain the data pages: cluster key + non-key columns
9
The best cluster key is ever-increasing
M S D X A T F You can see lots of opinions about clustered index key. The best key is ever increasing. That means a date or ID column
10
The best cluster key is narrow and unique
11
The Best Clustered Key is Static
CHANGES
12
Non-Clustered Indexes
13
Non-Clustered Indexes
14
Non-clustered Index Structure
M D T Non-Leaf Levels A F S X A D F Leaf Level M S T X Non-leaf levels contain the Index Key Leaf levels contain the Index Key, Pointer to table row and Included Columns
15
Column Order Is Important!
LastName FirstName City
16
Key Lookups When the index just isn’t enough
17
Covering Indexes
18
Best Practices Index foreign keys Index keys used in searches
Avoid duplicate indexes Avoid indexes that are rarely used – unless there is a business reason DO NOT BLINDLY FOLLOW RECOMENDATIONS
19
Index Maintenance Maintenance Wizard Scripts Reorganize Rebuild
Rebuild at 30% fragmentation Reorg > 10% and < 30% Ignore small tables Record what is done
20
Resources Glenn Berry Blog: http://sqlserverperformance.wordpress.com/
Expert Performance Indexing for SQL Server 2012 by Jason Strate (Apress) Ola Hallengren maintenance solution: Duplicate index script: duplicate-indexes-on-sql-server/
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.