Execution Plan Interpretation

Reading operators, properties, plan shape, and actual-versus-estimated behavior.

92 associated posts86 primary posts

Performance Tuning

No, You Can’t Calculate the Tipping Point with Simple Percentages.

This morning, Greg Gonzalez (who I respect) posted about visualizing the tipping point with Plan Explorer (a product I respect), and he wrote: The tipping point is the threshold at which a query plan will "tip" from seeking a non-covering nonclustered index to scanning the clustered index or heap. The basic formula is: A clustered…

Read more about No, You Can’t Calculate the Tipping Point with Simple Percentages. 21 comments — Join the discussion
Performance Tuning

How to Think Like the Engine: When a Seek Isn’t

In our last episode, I introduced the concept of scan predicates: execution plan operations that weren't able to seek directly to the rows they needed. Let's take another query:
[crayon-6a7062c39cf43836271166/]
If we ONLY have the gray pages index on LastAccessDate, Id, DisplayName, and Age, our query plan looks like this:

I'm going to narrate this from bottom up because it makes for easier storytelling:

Read more about How to Think Like the Engine: When a Seek Isn’t 5 comments — Join the discussion
Performance Tuning

Never Judge A Query By Its Cost

Signs and Numbers
When tuning queries, or even finding queries to tune, there's a rather misguided desire to look for queries with a high cost, or judge improvement by lowering query cost. The problem is that no matter what you're looking at, costs are estimates, and often don't reflect how long a query runs for or the actual work involved in processing the query.

Read more about Never Judge A Query By Its Cost 7 comments — Join the discussion
Performance Tuning

“Surely this one will get a clustered index scan.”

I love building demos for our training classes because I'm constantly in a battle of the minds with SQL Server. I try to guess what he's going to do next, and I love it when he surprises me.

I started by building a new parameter sniffing demo with the Stack Overflow database, and in this case using the 50GB 2013 size. I wanted to demo a search stored procedure looking for the first few words of question titles.

Read more about “Surely this one will get a clustered index scan.” 25 comments — Join the discussion
Performance Tuning

Adventures In Foreign Keys 5: How Join Elimination Makes Queries Faster

FINALLY...
This is the last post I'll write about foreign keys for a while. Maybe ever.

Let's face it, most developers probably find them more annoying than useful, and if you didn't implement them when you first started designing your database, you're not likely to go back and start trying to add them in.

Read more about Adventures In Foreign Keys 5: How Join Elimination Makes Queries Faster 14 comments — Join the discussion
Performance Tuning

Is Cost Threshold for Parallelism Measured in Seconds?

SQL Server automatically chooses when to divide your query's work across multiple CPU cores. It makes that decision based on your query's cost. To see it, let's throw 1,000,000 tiny rows in a table: [crayon-6a7062c3a26e8161699305/] And with my server set at SQL Server's default settings (Cost Threshold of 5, MAXDOP of 0), count how many…

Read more about Is Cost Threshold for Parallelism Measured in Seconds? 2 comments — Join the discussion
Performance Tuning

When You Need to Tune A View, Don’t Just Get Its Plan

Say your database has a view, and everybody's queries use it. Let's take the Stack Overflow database and create this view:
[crayon-6a7062c3a40c3396825940/]
Not pretty, but that's why you're here, right? Real world code is ugly.

And say my users are running queries like these:
[crayon-6a7062c3a40cf345843572/]
Notice that the select, where, order by etc all have variations in them. They're not all asking for the same fields, which means SQL Server can make different decisions about:

Read more about When You Need to Tune A View, Don’t Just Get Its Plan 2 comments — Join the discussion

Do I Have A Query Problem Or An Index Problem?

Party Up
When someone says "this query is slow", and you can rule out contextual stuff like blocking, odd server load, or just an underpowered server, what's the first thing you look at? There's a lot of potential culprits, and they could be hiding in lots of different places.

After several minutes of thinking about it, I decided to call my method QTIP, because I like to look at the:

Read more about Do I Have A Query Problem Or An Index Problem? 7 comments — Join the discussion