Indexing presents daunting challenges, as it offers countless options to choose from. Even organizing indexes in an optimal fashion can be overwhelming. But with a little help from SQL Server domain expert Richard Douglas, you’ll see how to simplify indexing and improve the overall performance of your SQL Server applications.
Richard will provide step-by-step guidance to help you:
Find missing and unused indexes
Resolve fragmentation issues
Follow the golden rules of indexing
And much more
Read more: Presentations - 2013 | Richard Douglas - SQL Server Professional http://sql.richarddouglas.co.uk/presentations/presentations-2013#ixzz2l61TSSrj
Follow us: @SQLRich on Twitter
5. You need the big picture
5
Understanding Indices
Dell Software
6. Indexing strategies
It’s all about DWI knowledge:
D W I
a
t
a
6
Understanding Indices
o
r
k
l
o
a
d
n
t
e
r
n
a
l
s
Dell Software
7. Your host
• Richard Douglas
• Systems Consultant
• Editor in Chief - ToadWorld.com
• SQL Server MCITPro
• PASS Chapter Leader
• Blog: http://SQL.RichardDouglas.co.uk
• Twitter: @SQLRich
• Email: Richard.Douglas@Software.Dell.com
7
Understanding Indices
Dell Software
8. Agenda
• Pre requisites
• Understanding indexes and their architecture
• Utilising SQL Server DMO’s
• Index golden rules
• The importance of maintenance
8
Understanding Indices
Dell Software
9. Pre Requisites
Understanding the SQL Server Data Page
• A data page is 8KB (8192 bytes)
Page header
1 - Cooper
2 - Hofstadter
3 - Koothrappali
5 - Wolowitz
4 - Kripke
• Page header is 96 bytes leaving
8096 bytes for data
• Slot array stores the logical order
543 21
5
9
Understanding Indices
Dell Software
19. Missing Index Limitations
• Not intended to fine tune an indexing configuration.
• Only gathers 500 missing index groups.
• Optimal column orders for the index are not specified.
• In some scenarios it has been known to only return information on included columns.
• Returns only raw information about columns.
• Does not suggest filtered indexes.
• It can return different costs for the same missing index group that appears multiple times in XML
Showplans.
• Multiple similar indexes may be returned.
• Only considers non-trivial query plans.
19
Understanding Indices
Dell Software
20. Golden Rules for Clustered Indexes
Bad example; Surname, Firstname, Middle Initial
• Narrow
• Static
• Progressive
Impacts nonclustered indexes
Fragmentation
• Unique
• Fixed width
Space impact
• Not Null
This example will have 13 bytes of overhead alone;
• 4 byte uniquifier
• 2 byte variable offset + 6 bytes for variable length fields
• 1 byte for NULL values and NULL bitmap
20
Understanding Indices
Dell Software
21. Golden Rules for NonClustered Indexes
• Have an optimal clustered key
• Not narrow
• Reduce unnecessary overhead
– Fixed Width
– Not null
• Consolidate
• Index foreign keys
21
Understanding Indices
Dell Software
22. The importance of maintenance
Page split scenario
Page pointers
Page header
Data Row 1
Data Row 2
Data Row 3
Data Row 5
Data Row 4
Understanding Indices
Page header
Data Row 4
Data Row 5
5 321
22
Page header
Data Row 6
Data Row 7
Data Row 8
Data Row 9
Data Row 10
54
109876
Dell Software
23. Fragmentation
Two main types
• Logical / External
“When the next logical page is not
the next physical page”
– Significantly reduces scan
performance
– Can cause extra IO
• Physical / Internal
“When page density is sub
optimal”
– Increased storage space
– More room required in the buffer
pool
– More IO’s to read in the data
– More logging, bigger backups
23
Understanding Indices
Dell Software
24. Fixing fragmentation
• Rebuild Indexes
• Reorganize Indexes
• Options
– Maintenance plan
– Custom/community scripts
– Third party tools
• Guideline (sys.dm_db_Index_Physical_Stats provides these figures)
– 0 – 5% No action
– 5 – 30% Reorganize
– 30% + Rebuild
24
Understanding Indices
Dell Software
25. Maintenance best practices
• Auto Close
• Auto Shrink
• Statistics
• Recovery models
25
Understanding Indices
Dell Software