SQL Server Parameter Sniffing: Causes and Fixes for Unstable Query Performance
Parameter sniffing occurs when SQL Server builds and caches an execution plan based on the parameter values passed during a procedure's first run, and then reuses that plan for all later calls. This works well for evenly distributed data but can cause inconsistent slowdowns when data is skewed, such as a few customers with millions of rows and many with very few. The article explains how to spot the problem by comparing estimated and actual row counts or the compiled and runtime parameter values in execution plans. Suggested remedies include forcing a known good plan through Query Store, using OPTION (RECOMPILE) for infrequent queries, and applying OPTIMIZE FOR hints or separate code paths for outlier values. A covering index that makes one plan efficient across all values is presented as a more permanent solution.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in