I came across the sniffing parameter when one of my requests took much longer than expected. When I delved into this problem, I found out that:
When the first time query is executed, it (SQL Server) creates a execution plan for this query, and for another n times, when the same query is executed, and if it has a large variance in the result set at the first start, there is a problem with the sniff parameter "
It was in my script.
Now my question is: is there a way or workaround to overcome the sniffing option in SQL Server in these scripts?
I know by running sp_updatestats , I can check if this is happening or not.
And also I know, to catch the problem, I need to monitor the procedure cache, query_hash and query_plan_hash sys.dm_exec_query_stats I can do this.
I do not want to use the RECOMPILE in SET section, as this will create new execution plans each time the query is executed.
But instead of checking the problem, I want to overcome it by doing something in the request itself, I mean, for example, "Detecting a problem at runtime and creating a new execution plan only as needed (not every time)."
I often encounter the problem of sniffing parameters, so every useful suggestion and help will be greatly appreciated. Thanks in advance!
source share