You should hire Richie Rump. Here's why.

Category: Execution Plans

Performance Tuning

New Official Documentation on Forced Parameterization

I love me some documentation.

For years, I've pointed folks to the SQL Server 2008 documentation on Forced Parameterization, a really useful tool for reducing plan cache bloat, getting more accurate reusable query plans, and enabling SQL Server 2019 and 2022's Intelligent Query Plan features, many of which rely on the same query text coming in repeatedly over time in order to tune it. That documentation was pretty sparse, though.

Read more about New Official Documentation on Forced Parameterization 5 comments — Join the discussion
Performance Tuning

Row-Level Security Can Slow Down Queries. Index For It.

The official Azure SQL Dev's Corner blog recently wrote about how to enable soft deletes in Azure SQL using row-level security, and it's a nice, clean, short tutorial. I like posts like that because the feature is pretty cool and accomplishes a real business goal. It's always tough deciding where to draw the line on how much to include in a blog post, so I forgive them for not including one vital caveat with this feature.

Read more about Row-Level Security Can Slow Down Queries. Index For It. 3 comments — Join the discussion
Performance Tuning

Query Plan Pop Quiz Answers 2 and 3: I’ve Got Good News and Bad News.

In the Query Plan Pop Quiz, questions 2 and 3 asked you about what the sizes of arrows on query plans meant. The good news is that almost all of you got Question 2 right, but the bad news is that the vast majority of you got Question 3 completely incorrect, and the saddest part of that is that you've been using that inaccurate knowledge to guide your query tuning - and wasting your time.

Read more about Query Plan Pop Quiz Answers 2 and 3: I’ve Got Good News and Bad News. 5 comments — Join the discussion
Performance Tuning

Query Plans Pop Quiz Answer #1: Costs are Garbage.

In last week's Query Plans Pop Quiz, the first question was, someone hands you these two queries and you get their estimated plans to decide which query to tune. Perhaps you get the estimated plans from SSMS, or from sp_BlitzCache, or from your monitoring tool. The question was, which query should you focus on tuning?…

Read more about Query Plans Pop Quiz Answer #1: Costs are Garbage. 4 comments — Join the discussion
Performance Tuning

Query Plans Pop Quiz: Three Simple Questions

Question 1: Pick the Problematic Plan: someone hands you a pair of queries, and you get the estimated query plans. (Perhaps you get the estimated plans from SSMS, or from sp_BlitzCache, or from your monitoring tool.) Which one of these two should you focus on tuning first, Query 1 or Query 2?

Question 2: on an estimated plan, what does the thickness of the colored arrow represent?

Read more about Query Plans Pop Quiz: Three Simple Questions 28 comments — Join the discussion
Performance Tuning

SQL Server 2022 Finally Fixed a SQL Server 2008 Query Plan Bug!

For yeeeeeears, when I've explained execution plans, part of my explanation has included the instructions, "Read the plan from right to left, top to bottom, looking for the place where the estimates vs actuals are suddenly way off." Here's an example:

Things seem to be going okay on the query plan until you hit the key lookup, which brought back 13 rows of an estimated 19,452. That would appear to be a pretty doggone bad estimate.

Read more about SQL Server 2022 Finally Fixed a SQL Server 2008 Query Plan Bug! 5 comments — Join the discussion
Performance Tuning

Yes, Cardinality Estimation Keeps Changing After SQL Server 2014.

About 10 years ago, Microsoft made changes to the Cardinality Estimator (CE) which caused some problems for SQL Server upgrades. When folks upgraded to SQL Server 2014, they also casually switched their databases' compatibility level to the latest version, because for years that hadn't really affected query plans. They just figured they wanted the "latest and greatest" compat level, without regard to the effects. That backfired badly when they suddenly got 2014's Cardinality Estimation changes.

Read more about Yes, Cardinality Estimation Keeps Changing After SQL Server 2014. 4 comments — Join the discussion
Performance Tuning

What Happens When Multiple Queries Compile at Once?

An interesting question came in on PollGab. DBAmusing asked: If a query takes 5-7s to calculate the execution plan (then executes <500ms) if multiple SPIDS all submit that query (different param values) when there's no plan at start, does each SPID calc the execution plan, one after the other after waiting for the prior SPID…

Read more about What Happens When Multiple Queries Compile at Once? 5 comments — Join the discussion
Performance Tuning

What’s Faster: IN or OR? Columnstore Edition

Pinal Dave recently ignited a storm of controversy when he quizzed readers about which one of these would be faster on AdventureWorks2019:
[crayon-6a6b34116f953163467802/]
I laughed so hard when I saw the storm of responses on Twitter. People sure do get passionate about this kind of thing. If you ever wanna witness patience and generosity in action, look at Pinal's responses to this tweet.

Read more about What’s Faster: IN or OR? Columnstore Edition 19 comments — Join the discussion
Performance Tuning

Estimated and Actual Plans Can Have Different Shapes.

A reader posted a question for Office Hours: Hi Brent, What is your take on Hugo Kornelis's explanation of execution plan naming. As her his explanation, estimated exec plan is simply an execution plan whereas actual execution plan = execution plan+run-time stats. Do you agree that the naming is flawed and confusing? - Yourbiggestfan I…

Read more about Estimated and Actual Plans Can Have Different Shapes. 17 comments — Join the discussion
Performance Tuning

SQL Server 2022 Tells You Why A Query Can’t Go Parallel.

Until 2022, when a query couldn't go parallel, all we got was a really cryptic note in the execution plan properties saying NonParallelPlanReason = CouldNotGenerateValidParallelPlan.

But starting with SQL Server 2022, even when I'm running under older compatibility levels:
[crayon-6a6b341172fec816581507/]
The execution plan gives me way more details:

Read more about SQL Server 2022 Tells You Why A Query Can’t Go Parallel. 10 comments — Join the discussion
Performance Tuning

“I’m getting index seeks. Why are my row estimates still wrong?”

If you've got good indexes to support your query, and statistics to help SQL Server guess how many rows will come back, how can SQL Server still come up with terribly incorrect row estimates? To demonstrate, I'll use the 2018-06 version of the Stack Overflow database, but any recent version will work as long as…

Read more about “I’m getting index seeks. Why are my row estimates still wrong?” 11 comments — Join the discussion