A stored procedure is fast for one parameter value but slow for another. What would make you suspect parameter sniffing, and what evidence would you look for in the execution plan?
💡 Model Answer
Parameter sniffing occurs when the query optimizer uses the first parameter value it sees to compile a plan that is suboptimal for other values. You suspect it when the same stored procedure runs quickly for one value but slowly for another, yet the plan is identical. In the execution plan, look for a single plan that is reused across calls, with cardinality estimates that favor the first value. Check the estimated row counts for the parameterized predicate; if they differ drastically from actual counts, that indicates sniffing. You can also query sys.dm_exec_query_stats to see the plan hash and the number of executions. Evidence of sniffing includes a plan that scans many rows for one value but only a few for another, and the plan is not recompiled. To confirm, run the procedure with OPTION(RECOMPILE) or use local variables to force a new plan for each execution.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500