SlideShare a Scribd company logo
Why Did My Clever
Index Change
Backfire?
Kendra Little
March 21, 2018
Hi, I’m Kendra Little
• Path: Database Administrator, Consultant, Trainer
• Microsoft Certified Master
• Founder of SQLWorkbooks.com
@Kendra_Little
Ahh… blunders
Today’s blunders
Index cleanup accident
Frustrating filtered index
Ugly indexed view
Anti-blunder patterns
3
1
2
4
Frustrating filtered
index
A new process: ‘flagging’
• Table with hundreds of millions of rows
• Can have rapid inserts
• Small percentage of rows flagged for review
• After a row is reviewed, the flag is cleared
Sounds like a filtered index!
• Very selective
• Simple one-column predicate (no functions or
computed columns needed)
• Must update dynamically
We’ve used filtered indexes before
What could go wrong?
Demo: The filtered index that
literally couldn’t even
Ouch!
I wish I’d discovered that BEFORE deploying to
production
SET OPTIONS that affect results
https://technet.microsoft.com/en-us/library/ms175088.aspx
Blunders with filtered indexes
1. Can you create the filtered index?
• If the table was created with the wrong
settings, you can’t even create it
2. Will your code use the filtered index?
• “Unsafe” parameterization
3. Do inserts, updates, & deletes from the app work?
• Also test for indexed views and persisted
computed columns
The ugly indexed view
We need to support a new
aggregate query
• Table with hundreds of millions of rows
• Can have rapid inserts
• Simple query with one join
• Groups by YEAR([DATETIME2 column])
Sounds like a case for an
indexed view!
• Groups by a defined column
• Must update dynamically
We’ve used indexed views before…
But not on these tables
Demo: the ugly indexed view
The foreign key only helps in
the case of inserts
• If we allow updates to FirstName in ref.FirstName,
it is going to have to update the indexed view
• That will be slow unless we add a nonclustered
index on dbo.FirstNameByBirthDate to make
finding related rows fast
Well… at least the insert
sorta worked this time?
Top blunders with indexed views
1. Problems with ‘SET’ options (like filtered indexes)
2. May be required to use NOEXPAND in code, even
with Enterprise Edition
3. INSERT, UPDATE, and DELETE statements may
need supporting nonclustered indexes on the base
tables for performance if foreign keys don’t “cover”
checking for related rows
The index cleanup
accident
We’re cleaning up indexes
We know that unneeded indexes waste resources
– Disk
– Memory (even pure duplicates may be read)
– Index maintenance time/perf
– CHECKDB time / perf
– Backup time / space,
– Overhead for data modifications
We’re going to clean up some duplicates
Demo: index cleanup accident
Not again!
What happened?
SQL Server only needs to lock an index if the column
being modified is in the index
The “near-duplicate” nonclustered index happened to
be a safe path for the select query
Removing that path allowed the deadlock to happen
Blunders with index cleanup
• Queries will fail if they hint an index which does not
exist
• Index changes can cause deadlocks (including
seemingly innocent index cleanup changes)
Avoiding blunders
Avoiding blunders
1. Test data modifications
2. Clean up indexes in batches
3. Capture top queries with plans before the change
1. Test data modifications
Test from the calling application
– Testing from SSMS isn’t enough
– Don’t skip the small tables
The “fancier” your indexes are, the more critical this
becomes
2. Clean up indexes in
batches
Prioritize and group index cleanup
– The more critical the database, the slower you
should go
– Handle the biggest opportunities first
– Search for indexes hinted by name in the
codebase
– Look out for deadlocks after index changes
– Document any indexes added to prevent
deadlocks in the source code
3. Capture top queries
It’s possible to hit a performance regression with any
change
Handling it afterward is much easier if you know what
the plan was like before!
Make a rollback plan
(and test it!)
Thank you for
watching!

More Related Content

KEY
Spreadsheet Errors Nm
PDF
Db performance optimization with indexing
PPT
Django orm-tips
DOCX
Advanced excel topics
PPTX
Improving Spreadsheet Test Practices
PPTX
Spreadsheets for developers
PPSX
Perfect Plagiarism v2
Spreadsheet Errors Nm
Db performance optimization with indexing
Django orm-tips
Advanced excel topics
Improving Spreadsheet Test Practices
Spreadsheets for developers
Perfect Plagiarism v2

Similar to Geek Sync | Why Did My Clever Index Change Backfire? (20)

PDF
Module 3 design and implementing tables
PPT
PPTX
Query Optimization in SQL Server
PPTX
dotnetMALAGA - Sql query tuning guidelines
PPTX
Partitioning kendralittle
PDF
Strategies for SQL Server Index Analysis
PPT
Indexing Strategies
PDF
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
PDF
Optimized cluster index generation
PPTX
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)
DOCX
Discussion unit 3 2203
PPTX
Top 10 tips for Oracle performance (Updated April 2015)
DOC
Obiee metadata development
PPTX
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019
PDF
Building better SQL Server Databases
PPTX
Getting to know oracle database objects iot, mviews, clusters and more…
PPTX
Optimizing Application Performance - 2022.pptx
PDF
sql server and ssms basics server administration.pdf
PDF
50 Shades of Fail KScope16
PPTX
Blackboard DevCon 2011 - Developing B2 for Performance and Scalability
Module 3 design and implementing tables
Query Optimization in SQL Server
dotnetMALAGA - Sql query tuning guidelines
Partitioning kendralittle
Strategies for SQL Server Index Analysis
Indexing Strategies
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
Optimized cluster index generation
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)
Discussion unit 3 2203
Top 10 tips for Oracle performance (Updated April 2015)
Obiee metadata development
7 Database Mistakes YOU Are Making -- Linuxfest Northwest 2019
Building better SQL Server Databases
Getting to know oracle database objects iot, mviews, clusters and more…
Optimizing Application Performance - 2022.pptx
sql server and ssms basics server administration.pdf
50 Shades of Fail KScope16
Blackboard DevCon 2011 - Developing B2 for Performance and Scalability
Ad

More from IDERA Software (20)

PPTX
The role of the database administrator (DBA) in 2020: Changes, challenges, an...
PPTX
Problems and solutions for migrating databases to the cloud
PPTX
Public cloud uses and limitations
PPTX
Optimize the performance, cost, and value of databases.pptx
PPTX
Monitor cloud database with SQL Diagnostic Manager for SQL Server
PPTX
Database administrators (dbas) face increasing pressure to monitor databases
PPTX
Six tips for cutting sql server licensing costs
PDF
Idera live 2021: The Power of Abstraction by Steve Hoberman
PDF
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
PDF
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
PDF
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
PDF
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
PDF
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
PDF
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
PDF
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
PPTX
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
PPTX
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
PPTX
Benefits of Third Party Tools for MySQL | IDERA
PPTX
Achieve More with Less Resources | IDERA
PPTX
Benefits of SQL Server 2017 and 2019 | IDERA
The role of the database administrator (DBA) in 2020: Changes, challenges, an...
Problems and solutions for migrating databases to the cloud
Public cloud uses and limitations
Optimize the performance, cost, and value of databases.pptx
Monitor cloud database with SQL Diagnostic Manager for SQL Server
Database administrators (dbas) face increasing pressure to monitor databases
Six tips for cutting sql server licensing costs
Idera live 2021: The Power of Abstraction by Steve Hoberman
Idera live 2021: Why Data Lakes are Critical for AI, ML, and IoT By Brian Flug
Idera live 2021: Will Data Vault add Value to Your Data Warehouse? 3 Signs th...
Idera live 2021: Managing Digital Transformation on a Budget by Bert Scalzo
Idera live 2021: Keynote Presentation The Future of Data is The Data Cloud b...
Idera live 2021: Managing Databases in the Cloud - the First Step, a Succes...
Idera live 2021: Database Auditing - on-Premises and in the Cloud by Craig M...
Idera live 2021: Performance Tuning Azure SQL Database by Monica Rathbun
Geek Sync | How to Be the DBA When You Don't Have a DBA - Eric Cobb | IDERA
How Users of a Performance Monitoring Tool Can Benefit from an Inventory Mana...
Benefits of Third Party Tools for MySQL | IDERA
Achieve More with Less Resources | IDERA
Benefits of SQL Server 2017 and 2019 | IDERA
Ad

Recently uploaded (20)

PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
top salesforce developer skills in 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
history of c programming in notes for students .pptx
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPT
Introduction Database Management System for Course Database
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Digital Strategies for Manufacturing Companies
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Introduction to Artificial Intelligence
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Transform Your Business with a Software ERP System
PDF
Nekopoi APK 2025 free lastest update
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
top salesforce developer skills in 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
history of c programming in notes for students .pptx
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction Database Management System for Course Database
Which alternative to Crystal Reports is best for small or large businesses.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
Digital Strategies for Manufacturing Companies
How to Migrate SBCGlobal Email to Yahoo Easily
Operating system designcfffgfgggggggvggggggggg
Introduction to Artificial Intelligence
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Digital Systems & Binary Numbers (comprehensive )
Designing Intelligence for the Shop Floor.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Transform Your Business with a Software ERP System
Nekopoi APK 2025 free lastest update

Geek Sync | Why Did My Clever Index Change Backfire?

  • 1. Why Did My Clever Index Change Backfire? Kendra Little March 21, 2018
  • 2. Hi, I’m Kendra Little • Path: Database Administrator, Consultant, Trainer • Microsoft Certified Master • Founder of SQLWorkbooks.com @Kendra_Little
  • 4. Today’s blunders Index cleanup accident Frustrating filtered index Ugly indexed view Anti-blunder patterns 3 1 2 4
  • 6. A new process: ‘flagging’ • Table with hundreds of millions of rows • Can have rapid inserts • Small percentage of rows flagged for review • After a row is reviewed, the flag is cleared
  • 7. Sounds like a filtered index! • Very selective • Simple one-column predicate (no functions or computed columns needed) • Must update dynamically We’ve used filtered indexes before What could go wrong?
  • 8. Demo: The filtered index that literally couldn’t even
  • 9. Ouch! I wish I’d discovered that BEFORE deploying to production
  • 10. SET OPTIONS that affect results https://technet.microsoft.com/en-us/library/ms175088.aspx
  • 11. Blunders with filtered indexes 1. Can you create the filtered index? • If the table was created with the wrong settings, you can’t even create it 2. Will your code use the filtered index? • “Unsafe” parameterization 3. Do inserts, updates, & deletes from the app work? • Also test for indexed views and persisted computed columns
  • 13. We need to support a new aggregate query • Table with hundreds of millions of rows • Can have rapid inserts • Simple query with one join • Groups by YEAR([DATETIME2 column])
  • 14. Sounds like a case for an indexed view! • Groups by a defined column • Must update dynamically We’ve used indexed views before… But not on these tables
  • 15. Demo: the ugly indexed view
  • 16. The foreign key only helps in the case of inserts • If we allow updates to FirstName in ref.FirstName, it is going to have to update the indexed view • That will be slow unless we add a nonclustered index on dbo.FirstNameByBirthDate to make finding related rows fast
  • 17. Well… at least the insert sorta worked this time?
  • 18. Top blunders with indexed views 1. Problems with ‘SET’ options (like filtered indexes) 2. May be required to use NOEXPAND in code, even with Enterprise Edition 3. INSERT, UPDATE, and DELETE statements may need supporting nonclustered indexes on the base tables for performance if foreign keys don’t “cover” checking for related rows
  • 20. We’re cleaning up indexes We know that unneeded indexes waste resources – Disk – Memory (even pure duplicates may be read) – Index maintenance time/perf – CHECKDB time / perf – Backup time / space, – Overhead for data modifications We’re going to clean up some duplicates
  • 23. What happened? SQL Server only needs to lock an index if the column being modified is in the index The “near-duplicate” nonclustered index happened to be a safe path for the select query Removing that path allowed the deadlock to happen
  • 24. Blunders with index cleanup • Queries will fail if they hint an index which does not exist • Index changes can cause deadlocks (including seemingly innocent index cleanup changes)
  • 26. Avoiding blunders 1. Test data modifications 2. Clean up indexes in batches 3. Capture top queries with plans before the change
  • 27. 1. Test data modifications Test from the calling application – Testing from SSMS isn’t enough – Don’t skip the small tables The “fancier” your indexes are, the more critical this becomes
  • 28. 2. Clean up indexes in batches Prioritize and group index cleanup – The more critical the database, the slower you should go – Handle the biggest opportunities first – Search for indexes hinted by name in the codebase – Look out for deadlocks after index changes – Document any indexes added to prevent deadlocks in the source code
  • 29. 3. Capture top queries It’s possible to hit a performance regression with any change Handling it afterward is much easier if you know what the plan was like before!
  • 30. Make a rollback plan (and test it!)

Editor's Notes

  • #4: I’ve lived through this so many times
  • #7: Filtered indexes introduced in sql server 2008.
  • #11: CX is ~3.3GB, ~146.5 million rows.
  • #13: This takes 10 seconds
  • #45: Even in Enterprise Edition
  • #68: Imagine that we have a procedure like this--  except it'd be smart enough to handle when zero rows are modified, error handling, etc.
  • #71: The second query is blocked