Parameter Sensitivity and Plan Reuse

Parameter sniffing, parameterization, recompilation, and cached-plan reuse.

62 associated posts60 primary posts

Performance Tuning

Research Paper Week: Plan Stitch: Harnessing the Best of Many Plans

Those of you who follow me on Instagram, Twitter, or Facebook know I'm taking most of August off for vacation. Erika and I spent the last couple of weeks in Telluride, had a brief stop in Sacramento for SQL Saturday, and this week we're touring wineries in Napa and Sonoma. As part of recharging, I…

Read more about Research Paper Week: Plan Stitch: Harnessing the Best of Many Plans 6 comments — Join the discussion
Performance Tuning

15 Reasons Your Query Was Fast Yesterday, But Slow Today

In rough order of how frequently I see 'em: There are different workloads running on the server (like a backup is running right now.) You have a different query plan due to parameter sniffing. The query changed, like someone did a deployment or added a field to the select list. You have a different query…

Read more about 15 Reasons Your Query Was Fast Yesterday, But Slow Today 20 comments — Join the discussion
Performance Tuning

Parameter Sniffing in SQL Server 2019: Adaptive Joins

So far, I've talked about how adaptive memory grants both help and worsen parameter sniffing, and how the new air_quote_actual plans don't accurately show what happened. But so far, I've been using a simple one-table query - let's see what happens when I add a join and a supporting index:
[crayon-6a6ece2087d84677903900/]
(Careful readers will note that I'm using a different reputation value than I used in the last posts - hold that thought. We'll come back to that.)

Read more about Parameter Sniffing in SQL Server 2019: Adaptive Joins 1 comment — Join the discussion
Performance Tuning

Parameter Sniffing in SQL Server 2019: Air_Quote_Actual Plans

My last post talked about how parameter sniffing caused 3 problems for a query, and how SQL Server 2019 fixes one of them - kinda - with adaptive memory grants.

However, the post finished up by talking about how much harder performance troubleshooting will be on 2019 because your query's memory grant is based on the last set of parameters used, not the current set.

Read more about Parameter Sniffing in SQL Server 2019: Air_Quote_Actual Plans Be the first to comment
Performance Tuning

Parameter Sniffing in SQL Server 2019: Adaptive Memory Grants

This week, I'm demoing SQL Server 2019 features that I'm really excited about, and they all center around a theme we all know and love: parameter sniffing.

If you haven't seen me talk about parameter sniffing before, you'll probably wanna start with this session from SQLDay in Poland. This week, I'm going to be using the queries & discussion from that session as a starting point.

Read more about Parameter Sniffing in SQL Server 2019: Adaptive Memory Grants 18 comments — Join the discussion
Performance Tuning

Sniffed Nulls and Magic Numbers

I Sniff Your Milkshake
Building off of A Simple Stored Procedure Pattern To Avoid, I wanted to talk about a similar one that I see quite often that is not nearly as clever as one would imagine.

I goes something like this: If this variable is passed in as NULL, substitute it with something else. It has a lot of variations.
[crayon-6a6ece2091a0a124325718/]
They all have the desired effect: substituting a passed in NULL with a magic number.

Read more about Sniffed Nulls and Magic Numbers 8 comments — Join the discussion

[Video] Office Hours 2018/6/27 (With Transcriptions)

This week, Brent, Erik, Tara, and Richie discuss using SQL Server 2016 vs 2017 for production environment, reporting, reindexing jobs, Azure vs Amazon, parameter sniffing, creating custom alerts for agent jobs, activity monitor, troubleshooting SQL Server 2014, replication, turning off auto-updating stats on tempdb, and why Brent can't get a tan.

Here’s the video on YouTube:

Read more about [Video] Office Hours 2018/6/27 (With Transcriptions) 2 comments — Join the discussion
Performance Tuning

Table Valued Parameters: Unexpected Parameter Sniffing

Like Table Variables, Kinda
Jeremiah wrote about them a few years ago. I always get asked about them while poking fun at Table Variables, so I thought I'd provide some detail and a post to point people to.

There are some interesting differences between them, namely around how cardinality is estimated in different situations.

Read more about Table Valued Parameters: Unexpected Parameter Sniffing 10 comments — Join the discussion
Performance Tuning

Troubleshooting Parameter Sniffing Issues the Right Way: Part 3

In part 1 and part 2 of this series, I showed you the various ways to get the application's SET options so that you can get the same execution plan as the application. If you skip that step and run the query that is timing out in the application, it could be fast in SSMS. Your SET options must match the application's in order to reproduce the slowness users are seeing.

Read more about Troubleshooting Parameter Sniffing Issues the Right Way: Part 3 17 comments — Join the discussion
Performance Tuning

Troubleshooting Parameter Sniffing Issues the Right Way: Part 2

In part 1 of this series, I showed you how to get the compiled parameter values for an execution plan that you are investigating. You've identified it as a bad execution plan. You've already fixed the production emergency by removing the bad plan from the plan cache. You're almost ready to start testing for a workaround or a solution to avoid this issue in the future.

Read more about Troubleshooting Parameter Sniffing Issues the Right Way: Part 2 24 comments — Join the discussion
Performance Tuning

ColumnStore Indexes: Rowgroup Elimination and Parameter Sniffing In Stored Procedures

Yazoo
Over on his blog, fellow Query Plan aficionado Joe Obbish has a Great Post, Brent® about query patterns that qualify for Rowgroup Elimination. This is really important to performance! It allows scans to skip over stuff it doesn't need, like skipping over the dialog in, uh... movies with really good fight scenes.

Car chases?

Read more about ColumnStore Indexes: Rowgroup Elimination and Parameter Sniffing In Stored Procedures 5 comments — Join the discussion