5 ways to improve performance through indexing

Post on 25-Dec-2014

740 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

5 Ways to Improve Performance through Indexing

Jason Strate

e: jstrate@pragmaticworks.com

e: jasonstrate@gmail.com

b: www.jasonstrate.com

t: StrateSQL

Resources jasonstrate.com/go/indexing

Introduction

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Indexes

Disappointment

5 Ways to Improve Performance through Indexing

Lookup Imbalance

Lookup Imbalance

• Excessive key lookups

– Exceed number of seeks

• Problems

– Increased CPU

– Increased IO

– Increased duration

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Case Study 1

• What’s wrong?

• Do you see the pattern?

• What do you do?

– Move clustered index

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Case Study 3

• What’s wrong?

• Do you see the pattern?

• What do you do?

– Add included columns

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

November 6-9, Seattle, WA

Lookup Imbalance• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Scan Heavy Indexes

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

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

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

November 6-9, Seattle, WA

Scan Heavy Indexes• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Filtered Indexes

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

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

Filtered Index Issue

• Filter Criteria

– Must be included

– Can not be parameterized

• Plan warning

– Unmatched indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

November 6-9, Seattle, WA

Filtered Indexes• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Missing Indexes

Missing Indexes

• Optimize through materialization

– Index versus statistics

• Three options

– Dynamic management views

– Database Engine TuningAdvisor

– Plan Cache

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Missing Indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

MISSING INDEXES!!!

November 6-9, Seattle, WA

Missing Indexes• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Foreign Key Indexes

Indexing Foreign Keys

• Foreign keys enforcement

– INSERT

– UPDATE

– DELETE

• Performed in background

• Unseen until a problem

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Case Study

Delete from SalesOrderHeader?

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Case Study

Delete from SalesOrderDetail?

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

Case Study

Delete from SalesOrderHeaderSaleReason?

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

November 6-9, Seattle, WA

Indexing Foreign Keys• Demo

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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

Learn More About Indexes

MAKING BUSINESS INTELLIGENT www.pragmaticworks.com

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: jstrate@pragmaticworks.com

Blog: www.jasonstrate.com

Resource: jasonstrate.com/go/indexing

top related