Advanced Index Tuning for SQL Server

5,258 views

Published on

How to make Microsoft SQL Server 2005 and 2008 go faster by querying the Dynamic Management Views (DMVs) to build new indexes and drop ones that aren't being used.

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

No Downloads
Views
Total views
5,258
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
233
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Advanced Index Tuning for SQL Server

  1. 1. Advanced Index Tuning<br />
  2. 2. Brent Ozar<br />SQL Server MVPfor Quest Software<br />SQLServerPedia Ed.<br />SQL, SAN, VM admin<br />Dot-com-crash experience<br />Performance freak<br />Twitter @BrentO<br />Blog: www.BrentOzar.com<br />Photo Source http://www.flickr.com/photos/vasta/415625308/<br />
  3. 3. Today’s Agenda<br />Passive Tuning<br />Active Tuning<br />Index Compression<br />The Silent Killer<br />Resources and Q&A<br />
  4. 4. Passive Tuning with DMVs<br />
  5. 5. DMV Tuning Lifecycle<br />
  6. 6. Removing Indexes<br />
  7. 7. Results<br />
  8. 8. Why Are Writes Different?<br />
  9. 9. Our Table: Items<br />
  10. 10. Indexes On An “Item” Table<br />Index #1:<br />UPC_Code<br />Index #2:<br />SupplierID<br />Index #3:<br />Category<br />QtyInStock<br />Photo licensed with Creative Commons from:http://www.flickr.com/photos/revolute/1944742197/<br />
  11. 11. Data In The Index<br />
  12. 12. But When It Changes…<br />
  13. 13. That’s Why…<br />
  14. 14. Our Query<br />
  15. 15. A Better Way: Includes<br />CREATE INDEX <br />IX_Category_Includes<br /> ON dbo.Items (Category)<br /> INCLUDE (QtyInStock)<br />
  16. 16. And When It Changes…<br />
  17. 17. Query Plan<br />
  18. 18. Remember, Never SELECT *<br />
  19. 19. Leave a Bread Crumb Trail<br />
  20. 20. DMV Tuning Lifecycle<br />
  21. 21. Missing Index Query<br />
  22. 22. Okay – Now What?<br />
  23. 23. When Do We Add Indexes?<br />
  24. 24. DMV Tuning Lifecycle<br />
  25. 25. Active Tuning: The Wizards<br />
  26. 26. Danger! Danger!<br />
  27. 27. The End Result<br />CREATE NONCLUSTERED INDEX [_dta_index_Activity_11_1977058079__K1_K4_K7_K5_K3] ON [dbo].[Activity] <br />(<br /> [ServerName] ASC,<br /> [ActivityTypeID] ASC,<br /> [StatusTypeID] ASC,<br /> [StartTime] ASC,<br /> [DatabaseID] ASC<br />)<br />
  28. 28. Rename Each Index<br />CREATE NONCLUSTERED INDEX [IX_ServerName_ActivityTypeID_StatusTypeID_StartTime_DatabaseID] ON [dbo].[Activity] <br />(<br /> [ServerName] ASC,<br /> [ActivityTypeID] ASC,<br /> [StatusTypeID] ASC,<br /> [StartTime] ASC,<br /> [DatabaseID] ASC<br />) ON [PRIMARY]<br />
  29. 29. Makes Ongoing Tuning Easier<br />
  30. 30. Active Tuning Summary<br />Don’t just click apply<br />Use smart names<br />Look for overlaps<br />Go passive first<br />
  31. 31. SQL 2008 Data Compression<br />
  32. 32. Estimating Compression<br />sp_estimate_data_compression_savings<br />@schema_name<br />@object_name<br />@index_id<br />@partition_number<br />@data_compression<br />
  33. 33. Index Compression Drawbacks<br />Enterprise Edition only<br />No inheritance<br />No automation<br />
  34. 34. The Silent Performance Killer<br />
  35. 35. Pretend You’re SQL Server<br />Photo Licensed with Creative Commons From http://www.flickr.com/photos/quacktaculous/3143079032/<br />
  36. 36. 13% to 460%Faster<br />
  37. 37. Absolutely No:<br />App changes<br />Vendor issues<br />Testing required<br />Guessing on indexes<br />Backfires<br />
  38. 38. Not All Unicorns and Roses<br />Standard Edition: Offline Only<br />Enterprise Edition: Most Online<br />Generates a lot of transaction logs<br />
  39. 39. The Native Solution<br />
  40. 40. The Better Way: T-SQL Code<br />
  41. 41. Don’t Reinvent The Wheel<br />
  42. 42. http://www.brentozar.com/go/faster<br />

×