diff --git a/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Repositories/SiteCallAuditRepository.cs b/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Repositories/SiteCallAuditRepository.cs index 0b0d608d..44188b1b 100644 --- a/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Repositories/SiteCallAuditRepository.cs +++ b/src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Repositories/SiteCallAuditRepository.cs @@ -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() .FromSqlInterpolated(sql)