Understanding SQL Server Indexes - 2013-11-19

546 views
470 views

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
546
On SlideShare
0
From Embeds
0
Number of Embeds
114
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Understanding SQL Server Indexes - 2013-11-19

  1. 1. Understanding Indices Richard Douglas
  2. 2. “Can’t you just put an index on it?” (Name withheld to protect the guilty) 2 Understanding Indices Dell Software
  3. 3. Fixing the problem 3 Understanding Indices Dell Software
  4. 4. What about Europe? 4 Understanding Indices Dell Software
  5. 5. You need the big picture 5 Understanding Indices Dell Software
  6. 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. 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. 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. 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
  10. 10. Index Architectures 10 Dell Software Group
  11. 11. Index Architecture Heaps Clustered Indexes Nonclustered Indexes Nonclustered Columnstore Indexes 11 Understanding Indices Dell Software
  12. 12. Heap Structure 12 Understanding Indices Dell Software
  13. 13. Clustered Index Structure 13 Understanding Indices Dell Software
  14. 14. Nonclustered Index Structure 14 Understanding Indices Dell Software
  15. 15. Columnstore pages 15 Understanding Indices Dell Software
  16. 16. Index options Fill factor Pad Index Filtered index (WHERE) Include Data Compression Online 16 Understanding Indices Dell Software
  17. 17. Hidden dangers Versioning Uniqifiers VARCHAR NULLS 17 Understanding Indices Dell Software
  18. 18. Introducing Index DMO’s • Admin – Sys.dm_db_index_physical_stats • Usage – Sys.dm_db_index_usage_stats – Sys.dm_db_index_operational_stats • Missing – Sys.dm_db_missing_index_details – Sys.dm_db_missing_index_columns – Sys.dm_db_missing_index_groups – Sys.dm_db_missing_index_group_stats 18 Understanding Indices Dell Software
  19. 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. 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. 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. 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. 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. 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. 25. Maintenance best practices • Auto Close • Auto Shrink • Statistics • Recovery models 25 Understanding Indices Dell Software
  26. 26. Summary Architecture Options Querying Design Fragmentation Maintenance 26 Understanding Indices Dell Software
  27. 27. Solution Area Product Description Backup and Recovery Fast, flexible backup and recovery with industry-leading compression technology Performance & Operations Discover and resolve performance issues in production before they impact end users and service levels Deepest possible understanding of database performance and norms Performance Tuning Plan and develop applications that deliver both functionality and Development optimal performance Comprehensive schema, object, security and change management Administration Community, Knowledge, Training Project Lucy © 2012 Quest Software Inc. All rights reserved. Community crowdsourcing for SQL Server tracing and performance information! Pg. 27
  28. 28. SQLRelay Dates           @SQLRelay2013 11/11/13 – Reading 12/11/13 – Southampton 13/11/13 – Cardiff 14/11/13 – Birmingham 15/11/13 – Hemel Hempstead 25/11/13 – Newcastle 26/11/13 – Manchester 27/11/13 – Norwich 28/11/13 – Bristol 29/11/13 – London
  29. 29. Any questions? 29 Understanding Indices Dell Software
  30. 30. Thank you Richard.Douglas@Software.Dell.com @SQLRich

×