Problem Statement
Describe a strategy to stabilize performance for a parameterized search endpoint suffering from plan cache instability.
Explanation
Segment queries so highly skewed predicates use a dedicated path. For example, branch on a flag to call a version optimized for rare values. Use parameterization with sensible defaults, and consider OPTIMIZE FOR or recompile hints cautiously when estimates are volatile.
Add supporting indexes that match the common filter patterns, and ensure statistics contain histograms on skewed columns. Monitor with plan hash and track regressions when distributions shift.
Code Solution
SolutionRead Only
-- Example branching IF @IsRare=1 SELECT ... WHERE country='VA' OPTION (RECOMPILE); ELSE SELECT ... WHERE country=@country;
Practice Sets
This question appears in the following practice sets:
