Status: Reviewed (deep-dive v1)
Stack note: Warehouse usp_* boards (SQL-12) compile with the first parameter set — a tiny @SqlInstanceId plan can torture the “all instances” call (or the reverse). Ties to SQL-16/20.
Goal: Spot sniffing, fix with measured options — not cargo-cult RECOMPILE on everything.
| Symptom | Likely sniffing? | First move |
|---|---|---|
| Same proc fast in SSMS, slow in Blazor | Often (different params / settings) | Actual plans both ways; QS (SQL-20) |
| Fast after deploy, slow next morning | Stats + new sniff | Compare plans in QS |
Only bad when @Id IS NULL (all rows) |
Classic | Separate proc or RECOMPILE on that path |
| Always slow | Missing index / blocking — not sniffing | SQL-16 / SQL-18 |
SQL Server caches a plan optimized for the sniffed parameter values at compile. Skewed estates (one huge instance, many tiny) make one plan a bad fit for others.
OPTION (RECOMPILE) on the statement — fresh plan each call; OK for heavy boards called moderately OPTIMIZE FOR (@p UNKNOWN) / known value — deliberate; document GetBoard vs GetBoardForInstance -- targeted recompile on the hot statement
SELECT … FROM dbo.Alert a
WHERE (@SqlInstanceId IS NULL OR a.SqlInstanceId = @SqlInstanceId)
OPTION (RECOMPILE);
-- optimize for unknown (density-based)
OPTION (OPTIMIZE FOR UNKNOWN);
usp_* WITH RECOMPILE OPTION (RECOMPILE) — confirm both acceptable SQL Dude — SQL-24 Parameter Sniffing v1