Indexing and Statistics

Designing, evaluating, maintaining, and troubleshooting indexes and statistics.

568 associated posts270 primary posts

Performance Tuning

Filtered Indexes vs. Table Partitioning

It was a dark and stormy… Oh, wrong story. It was actually a warm, sunny afternoon in Charlotte, NC. I was presenting “Index Methods You’re Not Using” at PASS Summit. In this talk, I discussed how indexed views, filtered indexes, and compressed indexes can improve your query performance by reducing I/O.

From stage right, an intrepid audience member raised his hand and asked, “Can you think of an example of when you would use filtered indexes instead of partitioning?”

Read more about Filtered Indexes vs. Table Partitioning 7 comments — Join the discussion
Performance Tuning

What You Can (and Can’t) Do With Indexed Views

Views are logical objects in SQL Server databases that present you with a “virtual table”. Views are typically created for one of three reasons: security, simplification, or aggregation. Security: we create views so that a user can read specific columns out of certain tables, but not all the data. Simplification: sometimes, it’s easier to write…

Read more about What You Can (and Can’t) Do With Indexed Views 32 comments — Join the discussion

How to Winterize Your Database

In Michigan where I grew up, we pull the boats out of the water at the beginning of the fall. It's a bit of a sad time, realizing we're done having fun on the water, and the seasons are about to change.

To prepare a boat for a few months of storage, we drain some fluids, replace others, give it a good cleaning, do some basic maintenance, and put on a tight waterproof cover.

Read more about How to Winterize Your Database 5 comments — Join the discussion
Performance Tuning

Filtered Indexes and Dynamic SQL

I’ve been told that an attendee at the PASS Summit pre-conference event asked about using dynamic SQL to get around some of the problems with filtered indexes. I’m not entirely sure what the question was, but it did give me the opportunity to play around with filtered indexes and write some simple demo code to illustrate just the kind of shenanigans that you can get up to.

Read more about Filtered Indexes and Dynamic SQL 21 comments — Join the discussion
T-SQL & Development

What Developers Need to Know About SQL Server

What Developers Need to Know About Designing Databases
https://twitter.com/SQLintheWild/status/393386854000492545

One of my favorite tips, and I never thought of it that way. Code is agile, and databases are brittle. It seems easy to refactor the database in the beginning, but as your app grows and more stuff interfaces with it, life gets a lot harder.

Read more about What Developers Need to Know About SQL Server 1 comment — Join the discussion
Performance Tuning

Trivial Optimization and Missing Indexes in SQL Server

Recently, Jes asked the team an index tuning question: "If a query has an index hint in it, will the optimizer ever suggest a missing index for that query?"

I immediately loved the question because I'd never really thought about it before. I typically think of index hints as being a very risky game and avoid them whenever I can-- after all if someone drops the index you've hinted, any query hinting a non-existent index will start to fail. (That's a really bad day!)

Read more about Trivial Optimization and Missing Indexes in SQL Server 7 comments — Join the discussion
Performance Tuning

How to Find ‘Secret Columns’ in Nonclustered Indexes

sp_BlitzIndex® just can't keep a secret. That's a feature, not a bug. I wrote sp_BlitzIndex® specifically so that it would rat out some things that SQL Server is doing behind the scenes to secretly help you out-- because it's really better if you know about it. What are secret columns? SQL Server needs a unique…

Read more about How to Find ‘Secret Columns’ in Nonclustered Indexes 21 comments — Join the discussion
Performance Tuning

Optimize for… Mediocre?

Some query hints sound too good to be true. And, unfortunately, usually they aren't quite as magical as they might seem.
Frustration with unpredictable execution times
People often learn about parameter sniffing when query execution times stop being predictable. Occasionally you'll hear about a stored procedure taking much longer than normal, but the next time you look, it might be faster.

Read more about Optimize for… Mediocre? 36 comments — Join the discussion
Performance Tuning

The Index Your Queries will Never Request (A Clustered Index!)

When it comes to indexes, SQL Server is really helpful. It lets you see what indexes queries are asking for both in execution plans, and missing index dynamic management views ("DMVs"). I like to look at the DMV missing index requests using sp_BlitzIndex®.

When you look at missing index requests, it's always important to remember one of the biggest things: these missing index requests won't ever ask for or recommend a specific clustered index.

Read more about The Index Your Queries will Never Request (A Clustered Index!) 3 comments — Join the discussion

3 Things You Need to Start Doing to Your Database Server

Taking care of your health is incredibly important (says the marathon runner). Eating right, exercising, and getting plenty of rest help you stay healthy and perform optimally. Your database server’s health is important to your company’s health. You need to take regular backups, check for consistency, and keep indexes tuned for optimal performance. Here are…

Read more about 3 Things You Need to Start Doing to Your Database Server 14 comments — Join the discussion