Live classes start in 1d 06h 51m — Save your seat

Index Evaluation and Specialized Indexes

Missing-index advice, filtered indexes, columnstore, and over-indexing.

62 associated posts59 primary posts

Performance Tuning

Making TRY_CAST and TRY_CONVERT Queries Faster with Indexed Computed Columns

I know this is gonna sound crazy, but let's say you had a table where people stored all kinds of things in one column: dates, integers, file names, sale prices, file names, you name it. And let's say your application frequently ran a query looking for dates in that column, like this: [crayon-6ae69f2f9a396670029456/] Even if…

Read more about Making TRY_CAST and TRY_CONVERT Queries Faster with Indexed Computed Columns 2 comments — Join the discussion
Performance Tuning

How to Make SELECT COUNT(*) Queries Crazy Fast

When you run a SELECT COUNT(*), the speed of the results depends a lot on the structure & settings of the database. Let's do an exploration of the Votes table in the Stack Overflow database, specifically the 2018-06 ~300GB version where the Votes table has 150,784,380 rows taking up ~5.3GB of space.

I'm going to measure each method 3 ways:

Read more about How to Make SELECT COUNT(*) Queries Crazy Fast 27 comments — Join the discussion

Research Paper Week: Query Execution in Column-Oriented Database Systems

This week, I'm sharing some of my favorite papers that I've read. Sometimes they're about future technologies that haven't shipped yet - and may never ship! Sometimes, like this one, they're not from Microsoft at all, but from someone else in the industry who's explaining a problem that we face in SQL Server. SQL Server…

Read more about Research Paper Week: Query Execution in Column-Oriented Database Systems 1 comment — Join the discussion
Performance Tuning

Yet Another Way Missing Index Requests are Misleading

Graduates of my Mastering Index Tuning class will already be familiar with the handful of ways the missing index DMVs and plan suggestions are just utterly insane. Let's add another oddity to the mix: the usage counts aren't necessarily correct, either. To prove it, Let's take MattDM's Stack Exchange query, "Who brings in the crowds?" He's…

Read more about Yet Another Way Missing Index Requests are Misleading 5 comments — Join the discussion
Performance Tuning

Indexed View Creation And Underlying Indexes

Accidental Haha
While working on some demos, I came across sort of funny behavior during indexed view creation and how the indexes you have on the base tables can impact how long it takes to create the index on the view.

Starting off with no indexes, this query runs in about six seconds.
[crayon-6ae69f2fa6384217948701/]
Here's the plan and the query stats:

Read more about Indexed View Creation And Underlying Indexes 1 comment — Join the discussion
Performance Tuning

Filtered Indexes vs Parameterization (Again)

At First I Was Like... This won't work at all, because parameters are a known enemy of filtered indexes. But it turns out that some filtered indexes can be used for parameterized queries, whether they're from stored procedures, dynamic SQL, or in databases with forced parameterization enabled. Unfortunately, it seems limited to filtering out NULLs…

Read more about Filtered Indexes vs Parameterization (Again) 2 comments — Join the discussion
Performance Tuning

Index Tuning Week: My D.E.A.T.H. Method for Tuning Indexes

This week I'm running a series of posts introducing the fundamentals of index tuning. Yesterday, I used Brent's 5 and 5 Rule to explain why you want to aim for around 5 indexes per table, and 5 columns (or less) per index. Now, how do we get from our current database situation to a better place?

When someone hands me a database and tells me to make it go faster without changing the code, I start with my D.E.A.T.H. Method:

Read more about Index Tuning Week: My D.E.A.T.H. Method for Tuning Indexes 2 comments — Join the discussion
Performance Tuning

Unused Indexes – Are they really unused or have they just not been used YET?

During our Critical Care® sessions with clients, we often see unused indexes (reads=0) with high writes. Sometimes these unused indexes have very high writes. If an index is never being used to help with performance but SQL Server is having to maintain it for INSERT, UPDATE and DELETE operations, then why keep the index around?

Read more about Unused Indexes – Are they really unused or have they just not been used YET? 12 comments — Join the discussion
Performance Tuning

Should Index Changes Require Change Control?

We got a phenomenal series of questions from a client, and I wanted to encapsulate the answers into a blog post to help more folks out: Should all index changes require testing in a staging environment, no matter how big or small? What would be a reasonable timeline duration from index identification to deployment? What…

Read more about Should Index Changes Require Change Control? 9 comments — Join the discussion
Performance Tuning

[Video] Interpreting Missing Index Recommendations

This week, we're sharing Instant Replay videos from our training classes. Next up is Pinal Dave talking about missing index requests from the dynamic management views. It doesn't matter whose script you use - they're all built atop SQL Server's missing-index DMVs, and they all have the same limitations. Treat the missing index requests the same way you would treat appetizers in a restaurant - if you order an appetizer and it's no good, don't order more dishes.

Read more about [Video] Interpreting Missing Index Recommendations Be the first to comment

How to Fix sp_BlitzIndex Aggressive Indexes Warnings

sp_BlitzIndex gives your indexes a psychiatrist-style evaluation. It's a lot like a real psychiatrist: it's just flagging behaviors, and there's not necessarily anything wrong with being a hoarder, or a workaholic, or a furry. They're just behavioral traits. Let your freak flag fly. One of the warnings is "Aggressive Indexes," which means sys.dm_db_operational_stats reports minutes of…

Read more about How to Fix sp_BlitzIndex Aggressive Indexes Warnings 14 comments — Join the discussion
Performance Tuning

Do Disabled Indexes Affect Missing Index Recommendations?

I'm so glad you asked! Let's take a look. Open up the Stack Overflow database, turn on actual execution plans, and run a query that will cause SQL Server to beg and plead for an index:
[crayon-6ae69f2fa80a8188870435/]
And we get a missing index recommendation in the plan:

Now create the index, and try the query again:
[crayon-6ae69f2fa80ad399521163/]
Oh, don't act like you haven't done that. And sure enough, SQL Server uses the index:

Read more about Do Disabled Indexes Affect Missing Index Recommendations? 8 comments — Join the discussion
Performance Tuning

Why Columnstore Indexes May Still Do Key Lookups

I was a bit surprised that key lookups were a possibility with ColumnStore indexes, since "keys" aren't really their strong point, but since we're now able to have both clustered ColumnStore indexes alongside row store nonclustered indexes AND nonclustered ColumnStore indexes on tables with row store clustered indexes, this kind of stuff should get a closer look.

Read more about Why Columnstore Indexes May Still Do Key Lookups 10 comments — Join the discussion
Performance Tuning

Optional Parameters and Missing Index Requests

That's when it all gets blown away
At one point or another in everyone's SQL-querying career, they end up writing a query that goes something like this:
[crayon-6ae69f2fa9693546875216/]
These are often called optional parameters, and if you spend any time looking at queries, this will make you shudder for many reasons. Poor cardinality estimates, full scans, etc.

Read more about Optional Parameters and Missing Index Requests 11 comments — Join the discussion