Repost: Watch out for SQL Server Parameter Sniffing
I posted on this about a year ago. I am reposting this as a Public Service Announcement (otherwise known as a PSA).
Do you have a stored procedure where the amount of data returned can vary wildly depending on what parameters are passed in? Does performance change dramatically depending on how much data is being returned? You could be a victim of SQL Server Parameter sniffing.
Luckily there is an easy fix that doesn?t involve medication?but you might have to change some of your code, just a little bit.
Take your standard stored procedure:
And make the following (highlighted) changes.
Also note: if you read through the links of my previous post, you will see this issue affects more than just SQL Server.