What reasons would you NOT choose to enable forced parameterization over simple parameterization for ad-hoc queries in SQL Server?
Is there a performance overhead? If so would it not be offset by the (possible) gains made by re-used query plans?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Have you analyzed your plan cache to see if you have a high number of single-use plans?
Have you considered the ‘optimize for ad hoc workloads‘ setting, which at least only stores a stub for the plan until it has been used more than once? I’ve found this to be quite effective.
If you have a lot of ad hoc SQL and you are seeing plan cache bloat, it can’t hurt to try forced parameterization. But you should thoroughly test your entire workload, since there are cases where the overhead can outweigh the gains (in particular if you make heavy use of indexed views, persisted computed columns, or partitioning you may end up with worse plans). It is important to note that when you turn this setting on, it also runs a
DBCC FREEPROCCACHEfor you, so expect a little hiccup where all of your existing plans will need to be re-compiled the next time they are needed. (Of course this has far less noticeable impact in the case where you already have ‘optimize for ad hoc’ combined with lots of single-use plans, since you’re mostly evicting stubs that would probably get flushed before re-used anyway.)Also note that there are many cases where this setting has no effect on individual queries (see the Books Online topic).