5 ways to improve performance through indexing

41
5 Ways to Improve Performance through Indexing

Upload: jason-strate

Post on 25-Dec-2014

741 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 5 ways to improve performance through indexing

5 Ways to Improve Performance through Indexing

Page 2: 5 ways to improve performance through indexing

Jason Strate

e: [email protected]

e: [email protected]

b: www.jasonstrate.com

t: StrateSQL

Resources jasonstrate.com/go/indexing

Introduction

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 3: 5 ways to improve performance through indexing

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

• Founded 2008 by MSFT MVP Brian Knight• Focused on the MSFT SQL Server Platform• Provides services, training and software• MSFT/HP “go to” partner: • Gold Certified:

o BIo Data Managemento SQL Performance

• Team led by multiple MVP’s• Offices throughout the US with Corporate

HQ in Jacksonville, FL

Pragmatic Works Company History

Page 4: 5 ways to improve performance through indexing

Indexes

Page 5: 5 ways to improve performance through indexing

Disappointment

Page 6: 5 ways to improve performance through indexing

5 Ways to Improve Performance through Indexing

Page 7: 5 ways to improve performance through indexing

Lookup Imbalance

Page 8: 5 ways to improve performance through indexing

Lookup Imbalance

• Excessive key lookups

– Exceed number of seeks

• Problems

– Increased CPU

– Increased IO

– Increased duration

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 9: 5 ways to improve performance through indexing

Possible Solutions

• Ignore the problem

– Choose high key lookup rate

• Move clustered index

– Maybe the key is wrong

• Add included columns

– Improve NC indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 10: 5 ways to improve performance through indexing

Case Study 1

• What’s wrong?

• Do you see the pattern?

• What do you do?

– Move clustered index

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 11: 5 ways to improve performance through indexing

Case Study 2

• What’s wrong?

• Do you see the pattern?

• What do you do?

– Move clustered index

– Add included columns

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 12: 5 ways to improve performance through indexing

Case Study 3

• What’s wrong?

• Do you see the pattern?

• What do you do?

– Add included columns

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 13: 5 ways to improve performance through indexing

November 6-9, Seattle, WA

Lookup Imbalance• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 14: 5 ways to improve performance through indexing

Lookup Imbalance Summary

• Key lookups should not exceed seeks

• Investigate “WHY” when they do

• Consider whether to:

– Move the clustered index

– Add included columns to non-clustered indexes

• Usage patterns will shift over time

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 15: 5 ways to improve performance through indexing

Scan Heavy Indexes

Page 16: 5 ways to improve performance through indexing

Scan Heavy Indexes

• High scans on large indexes

– Exceed seeks

• Problems

– Increased IO

– Increased locking

• Potential deadlocks

– Affect page life expectancy

– Impact memory distribution

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 17: 5 ways to improve performance through indexing

Case Study 1

• Metric is high, so what?

• How do you tie into performance counter?

– Sys.dm_db_index_usage_stats

– Plan cache

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Access Methods:Full Scans/sec

Page 18: 5 ways to improve performance through indexing

Case Study 2

• What’s wrong?

• Why aren’t the other indexes used?

• Are the right indexes in place?

• What do you do?– Examine execution plans

– Add in correct indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 19: 5 ways to improve performance through indexing

November 6-9, Seattle, WA

Scan Heavy Indexes• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 20: 5 ways to improve performance through indexing

Scan Heavy Indexes Summary

• High scans on indexes can impact performance– Higher IO

– More locking• More Blocking

• Possible Deadlocking

– Memory impacted

• Find the occurrences– Identify indexes and analyze plans

– Add alternative indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 21: 5 ways to improve performance through indexing

Filtered Indexes

Page 22: 5 ways to improve performance through indexing

Filtered Indexes

• Index with a WHERE clause – Only includes filtered rows

– Decreases rows in index

• Effect– Improved plan quality

– Improved storage

– Lower build time

– Less maintenance

• Benefit– Scan of small set of data

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 23: 5 ways to improve performance through indexing

Case Study

• New data coming this week– Represents < 1% of rows

• Can’t rebuild indexes– Statistics on new rows inaccurate

• Need high quality plans– Indexes in place aren’t used

• What do you do?

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 24: 5 ways to improve performance through indexing

Filtered Index Issue

• Filter Criteria

– Must be included

– Can not be parameterized

• Plan warning

– Unmatched indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 25: 5 ways to improve performance through indexing

November 6-9, Seattle, WA

Filtered Indexes• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 26: 5 ways to improve performance through indexing

Filtered Index Summary

• Consider filtered indexes for:

– Large indexes with limited range of use

– Tables with large number of new rows

• Improves index performance

– Smaller, lightweight, agile

– Improved plan quality

• Seeks over scans (small data over large data)

• Scans over seeks (tiny data over small data)

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 27: 5 ways to improve performance through indexing

Missing Indexes

Page 28: 5 ways to improve performance through indexing

Missing Indexes

• Optimize through materialization

– Index versus statistics

• Three options

– Dynamic management views

– Database Engine TuningAdvisor

– Plan Cache

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 29: 5 ways to improve performance through indexing

Missing Indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

MISSING INDEXES!!!

Page 30: 5 ways to improve performance through indexing

November 6-9, Seattle, WA

Missing Indexes• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 31: 5 ways to improve performance through indexing

Missing Index Summary

• These are FREE recommendations

– Results of actual performance opportunities

– Provide opportunity to focus on other needs

• These are recommendations

– Index schema to ensure value

– Consolidate when possible

– Review associated queries

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 32: 5 ways to improve performance through indexing

Foreign Key Indexes

Page 33: 5 ways to improve performance through indexing

Indexing Foreign Keys

• Foreign keys enforcement

– INSERT

– UPDATE

– DELETE

• Performed in background

• Unseen until a problem

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 34: 5 ways to improve performance through indexing

Indexing Foreign Key Issues

• Unindexed foreign key

– Constraint columns

• Performance issues

– Scan of column values

– Increased locking

– Blocking likely

– Potential deadlocking

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 35: 5 ways to improve performance through indexing

Case Study

Delete from SalesOrderHeader?

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 36: 5 ways to improve performance through indexing

Case Study

Delete from SalesOrderDetail?

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 37: 5 ways to improve performance through indexing

Case Study

Delete from SalesOrderHeaderSaleReason?

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 38: 5 ways to improve performance through indexing

November 6-9, Seattle, WA

Indexing Foreign Keys• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 39: 5 ways to improve performance through indexing

Indexing Foreign Key Summary

• Foreign keys are important

– Enforce integrity of data

– Constraints on values

• Operations occur in background

– DELETEs often source of issues

– Can lead to deadlocks

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 40: 5 ways to improve performance through indexing

Learn More About Indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Page 41: 5 ways to improve performance through indexing

ServicesSpeed development through training, and rapid development services from Pragmatic Works.

ProductsBI products to covert to a Microsoft BI platform and simplify development onthe platform.

FoundationHelping those who do not have themeans to get into information technologyachieve their dreams.

For more information…

Name: Jason Strate

Email: [email protected]

Blog: www.jasonstrate.com

Resource: jasonstrate.com/go/indexing