This post has been republished via RSS; it originally appeared at: Azure Database Support Blog articles.
This last week I had a service request where our customer faced a high wait time due to a parameter sniffing. In this situation, our customer is not able to change any option of the query and they asked about if there is any other option to fix this issue.
We have several alternatives but I would like to share 3 of them besides other ones:
- I developed an application that is running a parametrized query like our customer has.
- As you could see we have a process that creates a cached plan.
- Once, you have identified the plan_handle, you could run the following DBCC FREEPROCCACHE(plan_handle) , you are going to clean the cache plan for this query and you are going to have a new execution plan with this compile value. Information: DBCC FREEPROCCACHE (Transact-SQL) - SQL Server | Microsoft Docs
- Other option that you have is to disable parameter sniffing in the database properties. But, you could have other performance issue for the rest of the queries.
Finally, you could use plan guide, for example:
- My C# is converted the TSQL is this way: (@Name nvarchar(200))SELECT count(Id) FROM PerformanceVarcharNVarchar Where TextToSearch = @Name
- If you need this info you could see it using the following TSQL if needed:
- I created a plan guide recompiling the query every time that I executed the query in this way:
- Finally, if I need to drop the plan guide, basically, I could run the following command to delete it: