Top Banner
STRATEGIES FOR INDEX ANALYSIS
41
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Strategies for SQL Server Index Analysis

STRATEGIES FOR INDEX ANALYSIS

Page 2: Strategies for SQL Server Index Analysis

INTRODUCTION

Jason Strate

e: [email protected]

e: [email protected]

b: www.jasonstrate.com

t: StrateSQL

Resources jasonstrate.com/go/indexing

Page 3: Strategies for SQL Server Index Analysis
Page 4: Strategies for SQL Server Index Analysis

Plan a Strategy

Page 5: Strategies for SQL Server Index Analysis

AGENDA

Introduction

Catalog Views

Dynamic Management Objects

Index Analysis

Analysis Case Studies

Page 6: Strategies for SQL Server Index Analysis

INTRODUCTION

IntroductionCatalog

Views

Dynamic Management

ObjectsIndex Analysis

Analysis Case Studies

Page 7: Strategies for SQL Server Index Analysis

GOALS

Provide a basis for tools in index

analysis

Introduce index analysis stored

procedure

Demonstrate index analysis case studies

Page 8: Strategies for SQL Server Index Analysis

CATALOG VIEWS

IntroductionCatalog

Views

Dynamic Management

ObjectsIndex Analysis

Analysis Case Studies

Page 9: Strategies for SQL Server Index Analysis

INDEX METADATA

• Methodology:

• Heaps or Clustered?

• Identical Indexes

• Overlapping Indexes

• Objects

• sys.indexes

• sys.index_columns

• sys.dm_db_partition_stats

Page 10: Strategies for SQL Server Index Analysis

FOREIGN KEYS?

Methodology

• Index your foreign key columns.

Objects:

• sys.foreign_keys

• sys.foreign_key_columns

Primarily an OLTP best practice

Page 11: Strategies for SQL Server Index Analysis

CATALOG VIEWSDemo

Page 12: Strategies for SQL Server Index Analysis

DYNAMIC MANAGEMENT OBJECTS

IntroductionCatalog

Views

Dynamic Management

ObjectsIndex Analysis

Analysis Case Studies

Page 13: Strategies for SQL Server Index Analysis

CAPTAIN OBVIOUS

Methodology

• Keep the indexes that you use

Objects

• sys.dm_db_index_usage_stats

• sys.dm_db_index_operational_stats

Page 14: Strategies for SQL Server Index Analysis

CAPTAIN OBVIOUS, AGAIN

Methodology

• Build indexes that your queries will find useful

Objects

• sys.dm_db_missing_index_details

• sys.dm_db_missing_index_groups

• sys.dm_db_missing_index_group_stats

Page 15: Strategies for SQL Server Index Analysis

IS IT MONEY?

Methodology

• Is it worth the maintenance?

Objects

• sys.dm_db_index_operational_stats

Page 16: Strategies for SQL Server Index Analysis

DID I JUST SAY MAINTENANCE?

Methodology

• Tuning is better than troubleshooting

Object

• sys.dm_db_index_physical_stats

Page 17: Strategies for SQL Server Index Analysis

DYNAMIC MANAGEMENT OBJECTSDemo

Page 18: Strategies for SQL Server Index Analysis

INDEX ANALYSIS

IntroductionCatalog

Views

Dynamic Management

ObjectsIndex Analysis

Analysis Case Studies

Page 19: Strategies for SQL Server Index Analysis

INDEX ANALYSIS

• Stored procedure

• SQL Server 2005 – 2014

• SQL Database

• Compiles Catalog/DMO in single view

• Filter by tables

• Provides single look at indexes

• Missing indexes

• Missing foreign key indexes

• Multiple outputs

• Detailed

• Realign

• Duplicate

• Overlapping

Page 20: Strategies for SQL Server Index Analysis

INDEX ANALYSISDemo

Page 21: Strategies for SQL Server Index Analysis

ANALYSIS CASE STUDIES

IntroductionCatalog

Views

Dynamic Management

ObjectsIndex Analysis

Analysis Case Studies

Page 22: Strategies for SQL Server Index Analysis

ALIGNMENT ISSUES

• Excessive key lookups

• Exceed number of seeks

• Problems

• Increased CPU

• Increased IO

• Increased duration

Page 23: Strategies for SQL Server Index Analysis

ALIGNMENT ISSUES

• Ignore the problem

• Choose high key lookup rate

• Move clustered index

• Maybe the key is wrong

• Add included columns

• Improve NC indexes

Page 24: Strategies for SQL Server Index Analysis

CASE STUDY 1

• What’s wrong?

• Do you see the pattern?

• What do you do?

• Move clustered index

Page 25: Strategies for SQL Server Index Analysis

CASE STUDY 2

• What’s wrong?

• Do you see the pattern?

• What do you do?

• Move clustered index

• Add included columns

Page 26: Strategies for SQL Server Index Analysis

CASE STUDY 3

• What’s wrong?

• Do you see the pattern?

• What do you do?

• Add included columns

Page 27: Strategies for SQL Server Index Analysis

INDEX ALIGNMENTDemo

Page 28: Strategies for SQL Server Index Analysis

SCAN HEAVY INDEXES

• High scans on large indexes

• Exceed seeks

• Problems

• Increased IO

• Increased locking• Potential deadlocks

• Affect page life expectancy

• Impact memory distribution

Page 29: Strategies for SQL Server Index Analysis

CASE STUDY 1

• Metric is high, so what?

• How do you tie into performance counter?

• Sys.dm_db_index_ usage_stats

• Plan cache

Access Methods:Full Scans/sec

Page 30: Strategies for SQL Server Index Analysis

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

Page 31: Strategies for SQL Server Index Analysis

SCAN HEAVY INDEXESDemo

Page 32: Strategies for SQL Server Index Analysis

MISSING INDEXES

• Optimize through materialization

• Index versus statistics

• Three options

• Dynamic management views

• Database Engine TuningAdvisor

• Plan Cache

Page 33: Strategies for SQL Server Index Analysis

MISSING INDEXESMISSING

INDEXES!!!

Page 34: Strategies for SQL Server Index Analysis

MISSING INDEXESDemo

Page 35: Strategies for SQL Server Index Analysis

INDEXING FOREIGN KEYS

• Foreign keys enforcement

• INSERT

• UPDATE

• DELETE

• Performed in background

• Unseen until a problem

Page 36: Strategies for SQL Server Index Analysis

INDEXING FOREIGN KEY ISSUES

• Unindexed foreign key

• Constraint columns

• Performance issues

• Scan of column values

• Increased locking

• Blocking likely

• Potential deadlocking

Page 37: Strategies for SQL Server Index Analysis

CASE STUDY

Delete from SalesOrderHeader?

Page 38: Strategies for SQL Server Index Analysis

CASE STUDY

Delete from SalesOrderDetail?

Page 39: Strategies for SQL Server Index Analysis

CASE STUDY

Delete from

SalesOrderHeaderSaleReason?

Page 40: Strategies for SQL Server Index Analysis

FOREIGN KEYSDemo

Page 41: Strategies for SQL Server Index Analysis

THANK YOU

Jason Strate

e: [email protected]

e: [email protected]

b: www.jasonstrate.com

t: StrateSQL

Resources jasonstrate.com/go/indexing