Parameter sniffing = On with Parameterization = forced. Which takes precedence?
-
17-01-2021 - |
Question
These two settings seem to contradict each other. One forces plan parameterization so that only one plan gets created. The other allows for multiple plans
If you have Parameterization = forced, should parameter sniffing be false, or does one take precedence?
Additional details
Regarding the comments below, parameter sniffing is a database scoped option as of SS 2016. (was a surprise to me too). See also: SQLShack: SQL Server 2016 Parameter Sniffing
Solution
These do not conflict. Parameter sniffing is the process that uses the parameter values when building a plan. Forced parameterization turns literals into parameters in queries.
So having both on will turn literals into parameters, but not use those values when estimating cardinality.
OTHER TIPS
Parameterization and sniffing are separate activities. An ad-hoc statement can be parameterized by SQL Server without parameter values being sniffed.
Paul White has an excellent blog post on : Parameter Sniffing, Embedding, and the RECOMPILE Options which covers both Parameter Sniffing and parameterization in detail with examples.