perf(site-call-audit): OPTION (RECOMPILE) on the optional-parameter query page

This commit is contained in:
Joseph Doherty
2026-07-09 09:12:50 -04:00
parent 6f5d60070c
commit 34337a8714
@@ -226,7 +226,14 @@ WHERE ({filter.Channel} IS NULL OR Channel = {filter.Channel})
AND ({(hasCursor ? 1 : 0)} = 0
OR CreatedAtUtc < {afterCreated}
OR (CreatedAtUtc = {afterCreated} AND TrackedOperationId < {afterIdString}))
ORDER BY CreatedAtUtc DESC, TrackedOperationId DESC;";
ORDER BY CreatedAtUtc DESC, TrackedOperationId DESC
-- Every filter above is the (@p IS NULL OR col = @p) optional-parameter shape, so a
-- single cached plan would be parameter-sniffed for whichever filters happened to be
-- non-null on first compile. RECOMPILE lets the optimizer prune the dead (@p IS NULL)
-- predicates per invocation and pick IX_SiteCalls_Status_Updated / IX_SiteCalls_NonTerminal
-- for the filters actually supplied (arch-review 04, P5). Per-invocation compile cost is
-- negligible at UI-page cadence.
OPTION (RECOMPILE);";
var rows = await _context.Set<SiteCall>()
.FromSqlInterpolated(sql)