advanced index tuning

43
© 2008 Quest Software, Inc. ALL RIGHTS RESERVED. Advanced Index Tuning

Upload: quest-software

Post on 12-Jul-2015

1.376 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Advanced Index Tuning

© 2008 Quest Software, Inc. ALL RIGHTS RESERVED.

Advanced Index Tuning

Page 2: Advanced Index Tuning

About Me: Brent Ozar

• SQL Server Expert for

Quest Software

• Former SQL DBA

• Managed >80tb SAN,

VMware

• Dot-com-crash

experience

• Specializes in

performance tuning

Page 3: Advanced Index Tuning

Today’s Agenda

• Passive Tuning: Using DMVs

• Active Tuning: Outsmarting the Wizards

• Compression for Indexes

• The Silent Performance Killer

• Resources and Q&A

Page 4: Advanced Index Tuning

Passive Tuning with DMVs

Page 5: Advanced Index Tuning

DMV Tuning Lifecycle

Remove Indexes

Add Indexes

Observe

Page 6: Advanced Index Tuning

Removing Indexes

Page 7: Advanced Index Tuning

Results

Page 8: Advanced Index Tuning

Why Are These Different?

Page 9: Advanced Index Tuning

Our Table: Items

Page 10: Advanced Index Tuning

Indexes On An “Item” Table

• Index #1:– UPC_Code

• Index #2:– SupplierID

• Index #3:– Category

– QtyInStock

Photo licensed with Creative Commons from:

http://www.flickr.com/photos/revolute/1944742197/

Page 11: Advanced Index Tuning

Data In The Index

Category Qty in Stock Item ID

Bacon 45 1

Bacon 47 2

Bacon 98 3

Bacon 110 5

Page 12: Advanced Index Tuning

But When It Changes…

Category Qty in Stock Item ID

Bacon 45 1

Bacon 42 2

Bacon 200 3

Bacon 110 5

Page 13: Advanced Index Tuning

That’s Why…

Page 14: Advanced Index Tuning

Adding a Formula Column

Page 15: Advanced Index Tuning

Our Query

Page 16: Advanced Index Tuning

A Better Way: Includes

CREATE INDEX

IX_Category_Includes

ON dbo.Items (Category)

INCLUDE (QtyInStock)

Page 17: Advanced Index Tuning

And When It Changes…

Category Qty in Stock Item ID

Bacon 45 1

Bacon 42 2

Bacon 200 3

Bacon 110 5

Page 18: Advanced Index Tuning

Query Plan

Page 19: Advanced Index Tuning

Remember, Never SELECT *

Page 20: Advanced Index Tuning

Leave a Bread Crumb Trail

Page 21: Advanced Index Tuning

DMV Tuning Lifecycle

Remove Indexes

Add Indexes

Observe

Page 22: Advanced Index Tuning

Missing Index Query

Page 23: Advanced Index Tuning

Okay – Now What?

Page 24: Advanced Index Tuning

When Do We Add More Indexes?

Page 25: Advanced Index Tuning

DMV Tuning Lifecycle

Remove Indexes

Add Indexes

Observe

Page 26: Advanced Index Tuning

Active Tuning: The Wizards

Page 27: Advanced Index Tuning

Danger! Danger!

Page 28: Advanced Index Tuning

The End Result

CREATE NONCLUSTERED INDEX

[_dta_index_Activity_11_1977058079__K1_K4_K7_K5_K3]

ON [dbo].[Activity]

(

[ServerName] ASC,

[ActivityTypeID] ASC,

[StatusTypeID] ASC,

[StartTime] ASC,

[DatabaseID] ASC

) ON [PRIMARY]

GO

Page 29: Advanced Index Tuning

Rename Each Index

CREATE NONCLUSTERED INDEX

[IX_ServerName_ActivityTypeID_StatusTypeID_StartTime_

DatabaseID] ON [dbo].[Activity]

(

[ServerName] ASC,

[ActivityTypeID] ASC,

[StatusTypeID] ASC,

[StartTime] ASC,

[DatabaseID] ASC

) ON [PRIMARY]

GO

Page 30: Advanced Index Tuning

Makes Ongoing Tuning Easier

Page 31: Advanced Index Tuning

Active Tuning Summary

• Don’t just apply the recommendations

• Use smart names

• Look for overlaps

• Take the passive approach first

Page 32: Advanced Index Tuning

SQL 2008 Data Compression

Page 33: Advanced Index Tuning

Estimating Compression

• sp_estimate_data_compression_savings– @schema_name

– @object_name

– @index_id

– @partition_number

– @data_compression

Page 34: Advanced Index Tuning

Index Compression Drawbacks

• Enterprise, Developer Editions only

• No inheritance, no automation

• Get scripts from www.SQLServerBible.com

Page 35: Advanced Index Tuning

The Silent Performance Killer

Page 36: Advanced Index Tuning

Pretend You’re SQL Server

Photo Licensed with Creative Commons From

http://www.flickr.com/photos/quacktaculous/3143079032/

Page 37: Advanced Index Tuning

Does It Really Matter?

The workload performance increase realized in the

small-scale environment ranged from 60 percent at

the low level of fragmentation to more than 460

percent at the highest level of fragmentation.

The workload performance increased realized for the

large-scale environment ranged from 13 percent at

the low fragmentation level to 40 percent at the

medium fragmentation level.

http://technet.microsoft.com/en-

us/library/cc966523.aspx

Page 38: Advanced Index Tuning

13-460% Faster, And…

• No app changes

• No vendor issues

• No testing required

• No guessing on indexes

• No backfires

• Fully supported

• Even recommended!

Page 39: Advanced Index Tuning

Not All Unicorns and Roses

• Standard Edition:

Offline Only

• Enterprise Edition:

Most Online

• Generates a lot of

transaction logs

Page 40: Advanced Index Tuning

The Native Solution

Page 41: Advanced Index Tuning

The Better Way: T-SQL Code

Page 42: Advanced Index Tuning

Don’t Reinvent The Wheel

Page 43: Advanced Index Tuning

Resources On The Web

• SQL Server Wiki and Script Library:

SQLServerPedia.com

• Scripts to Enable Compression Fast:

www.SQLServerBible.com

• Index Tuning & Maintenance:

SQLfool.com