Upload
quest-software
View
4.417
Download
5
Tags:
Embed Size (px)
DESCRIPTION
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.
Citation preview
© 2009 Quest Software, Inc. ALL RIGHTS RESERVED
For audio, please call the phone number in your invitation email. Audio will not come through your speakers.
Advanced Index Tuning
2
Brent Ozar• SQL Server MVP
for Quest Software• SQLServerPedia Ed.• SQL, SAN, VM admin• Dot-com-crash
experience• Performance freak• Twitter @BrentO• Blog: www.BrentOzar.com
Photo Source http://www.flickr.com/photos/vasta/415625308/
3
Today’s Agenda• Passive Tuning• Active Tuning• Index Compression• The Silent Killer• Resources and Q&A
4
Passive Tuning with DMVs
5
DMV Tuning Lifecycle
6
Removing Indexes
7
Results
8
Why Are Writes Different?
9
Our Table: Items
10
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/
11
Data In The Index
Category Qty in Stock Item ID
Bacon 45 1
Bacon 47 2
Bacon 98 3
Bacon 110 5
12
But When It Changes…
Category Qty in Stock Item ID
Bacon 45 1
Bacon 42 2
Bacon 200 3
Bacon 110 5
13
That’s Why…
14
Our Query
15
A Better Way: Includes
CREATE INDEX
IX_Category_Includes
ON dbo.Items (Category)
INCLUDE (QtyInStock)
16
And When It Changes…
Category Qty in Stock Item ID
Bacon 45 1
Bacon 42 2
Bacon 200 3
Bacon 110 5
17
Query Plan
18
Remember, Never SELECT *
19
Leave a Bread Crumb Trail
20
DMV Tuning Lifecycle
21
Missing Index Query
22
Okay – Now What?
23
When Do We Add Indexes?
24
DMV Tuning Lifecycle
25
Active Tuning: The Wizards
26
Danger! Danger!
27
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
)
28
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]
29
Makes Ongoing Tuning Easier
30
Active Tuning Summary• Don’t just click apply• Use smart names• Look for overlaps• Go passive first
31
SQL 2008 Data Compression
32
Estimating Compression
sp_estimate_data_compression_savings– @schema_name– @object_name– @index_id– @partition_number– @data_compression
33
Index Compression Drawbacks• Enterprise Edition only• No inheritance• No automation
34
The Silent Performance Killer
35
Pretend You’re SQL Server
Photo Licensed with Creative Commons From
http://www.flickr.com/photos/quacktaculous/3143079032/
36
13% to 460%
Faster
37
Absolutely No:• App changes• Vendor issues• Testing required• Guessing on indexes• Backfires
38
Not All Unicorns and Roses• Standard Edition: Offline Only• Enterprise Edition: Most Online• Generates a lot of transaction logs
39
The Native Solution
40
The Better Way: T-SQL Code
41
Don’t Reinvent The Wheel
42
http://www.brentozar.com/go/faster