Skip to main content

What is Parameter Sniffing and how do you fix it?

Junior MS SQL
Quick Answer SQL Server compiles a plan for a stored procedure using the first parameter values it sees. If those values are unusual (high selectivity vs. low), the cached plan is ideal for them but wrong for typical calls. Fix: OPTION(RECOMPILE), OPTIMIZE FOR hint, or local variable workaround to break plan reuse.

Answer

SQL optimizes a plan based on first-used parameter value. Fix options include using RECOMPILE, OPTIMIZE FOR UNKNOWN, or rewriting queries.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice