Parameter Sensitive Plan Optimization: When Does It Fire?

In brief

  • Parameter Sensitive Plan optimization is on by default in SQL Server 2025. It did nothing for a table where one customer held 60 percent of the rows. Its own event said why: SkewnessThresholdNotMet.
  • It is not about the heavy value’s share, and not about plan cost. Fourteen tables separate cleanly on one number. It is the heaviest value’s row count divided by the estimate for the compiled value.
  • In this lab the dispatcher plan appeared above a ratio somewhere between 90,000 and 122,500, and never below it.

A scientific diagram of Parameter Sensitive Plan optimization, with fourteen small circles arranged along a horizontal axis labelled ratio on a log scale, hollow circles on the left, filled circles on the right, and a shaded band between ninety thousand and a hundred and twenty thousand.

Parameter Sensitive Plan optimization is the feature that was supposed to end parameter sniffing. Compile one plan for the small customer, another for the giant, and dispatch each call to the right one.

I had a giant customer with 200,052 orders among accounts of 52. The same cached plan served both and cost the giant 613,018 reads. The feature was on. No dispatcher plan appeared.

So I set out to find where it does appear. It took fourteen tables.

What I ruled out first

Share. I built four order tables where the giant held 4.8, 16.7, 35.5 and 60 percent of all rows. Each had indexes on the customer and the date. No dispatcher on any of them.

Cost. All four plans were cheap, around 0.2, and the optimiser had stopped early with “good enough plan found”. So I added a constant subquery that scans 2.5 million rows, pushing the cost to 33.9 with full optimisation. Still nothing. A cross-join shape at cost 8.3, nothing.

Shape. With and without ORDER BY. SELECT star. Through sp_executesql instead of a procedure. Nothing.

Then I asked SQL Server why. There’s an extended event, parameter_sensitive_plan_optimization_skipped_reason, with a map of 45 reasons on this build. Three of them are thresholds: SkewnessThresholdNotMet, OtherThresholdNotMet and CompilationTimeThresholdExceeded.

My first capture proved nothing. I stopped the session before reading its ring buffer, and stopping empties it. That was my error and I’m leaving it in.

With an event file instead, every one of these compiles fired the same reason: SkewnessThresholdNotMet. The feature had looked at the predicate and named the problem. The skew wasn’t enough.

The event names the threshold and doesn’t print the number. The rest of this post is about measuring the number from the outside.

A positive control

Before you say a feature doesn’t fire, you need one case where it does. Otherwise you can’t tell “it never fires here” from “you’re measuring it wrong”.

A table of a million rows with one index. One value holds 990,001 rows. Each other value holds one. SELECT * WHERE val = @v, compiled for a small value.

Dispatcher plan. The statement text in the plan grew a clause I’d never typed: option (PLAN PER VALUE(...)). That’s the feature, working.

Now I had two ends of a rope. One end at 60 percent, no dispatcher and a SkewnessThresholdNotMet event. The other at 99 percent, a dispatcher and no skipped event at all. Somewhere in between was the boundary.

Finding the boundary, and a confound

Seven tables of 500,000 rows. The giant held 60, 70, 80, 90, 95, 98 and 99 percent, with the remainder spread over 10,000 other values. Compile each for a small value.

No dispatcher at 60, 70, 80 or 90. Dispatcher at 95, 98 and 99.

That looked like a share boundary near 95 percent. It wasn’t, and the confound is visible in the same table. As the giant grew, the small values shrank. Twenty rows each at 60 percent, 5 rows at 90, 2 rows at 95. Two things moved together.

Two scientific line plots sharing an axis, one rising and one falling, with an arrow showing they cross at the same point where the outcome changes.

Pulling them apart

Four more tables, built to move one thing at a time.

A 90 percent giant with the remainder spread so thin that each small value estimated at one row: dispatcher. A 95 percent giant with the remainder over only 1,000 values, 25 rows each: no dispatcher. An 80 percent giant, thin remainder: dispatcher. A 98 percent giant, 20 rows per small value: no dispatcher.

So it wasn’t the share. A 98 percent giant failed and an 80 percent giant passed. What mattered was the small side.

Then three more. They tested whether the rule was “small side under about two rows” or a ratio between the two.

A giant of only 50,000 rows with a one-row small side: no dispatcher. A giant of 250,000 with the same one-row small side: dispatcher. A 98 percent giant with a four-row small side: dispatcher.

The first of those kills the absolute rule. A one-row small side wasn’t enough when the giant was small. The last one kills it from the other direction. Four rows was fine when the giant was big enough.

The number that separates all fourteen

Rows at the heaviest value, divided by the optimiser’s estimate for the value the plan was compiled for.

TableGiant rowsEstimate for compiled valueRatioDispatcher
60% giant, 10,000 others300,0002015,000no
95% giant, 1,000 others475,0002519,000no
70% giant350,0001523,333no
98% giant, 500 others490,0002024,500no
Orders table, 60% giant1,500,0505030,001no
80% giant400,0001040,000no
10% giant, thin remainder50,000150,000no
90% giant450,000590,000no
98% giant, four-row remainder490,0004122,500yes
95% giant475,0002237,500yes
50% giant, thin remainder250,0001250,000yes
80% giant, thin remainder400,0001400,000yes
90% giant, thin remainder450,0001450,000yes
99% giant495,0001495,000yes

Sorted by that ratio, the answers separate perfectly. Every table under 90,000 said no. Every table over 122,500 said yes. Nothing else I varied predicts the outcome. That describes these results, not the engine’s rule.

The problem I opened with, 200,052 orders against an estimate of 51.25, has a ratio of about 3,903. It sits far below the boundary I measured.

What I can and can’t claim

I can claim what fired and what didn’t on build 17.0.4085.5. That’s for a single equality predicate on an indexed integer column.

I can’t claim the engine computes this ratio. It may bucket cardinalities on a log scale. It may then require the compiled value and the heavy value to land far enough apart. That would produce the same boundary and I couldn’t tell the difference from outside.

I also can’t claim the boundary is exactly 100,000. It’s between 90,000 and 122,500. Two more tables would narrow it. They wouldn’t change the lesson.

The lesson about Parameter Sensitive Plan optimization

The documentation says the feature helps with skewed data. In these test cases on this build, it did at a ratio between 90,000 and 122,500. That’s the heaviest value’s rows against the estimate for the compiled value. It is an observed separation, not an established threshold.

A customer with 200,000 orders in a table where most have 50 is a skew of 4,000 to one. That’s a real production problem. It’s the one people mean when they say parameter sniffing, and in this lab the feature didn’t see it.

So the answer to “doesn’t 2025 handle this now” is: in this lab, yes for the rare giant. Not for the ordinary one. For the ordinary giant the fixes are still the old ones.

A scientific illustration of a ratio scale in three bands. Everything below ninety thousand is shaded as no dispatcher plan, a narrow band between ninety thousand and a hundred and twenty two thousand five hundred is marked boundary unresolved, and everything above it is shaded as dispatcher plan. The ordinary giant is marked at three thousand nine hundred and three.

If you’d like this run against your own skew before you rely on it, the fourteen scripts take an afternoon.

Skewed is not a feeling, it is a ratio, and I measured where this one starts to count.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Execution Plan, Query Hint, SQL Performance, SQL Scripts, SQL Statistics
Previous Post
tempdb: A Traveller’s Guide to Four Regions

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.