-- arch-review 2026-08-19 P5-2 (register row-35 class): the SiteCalls list page's -- sort key gets its own index. -- -- SiteCallAuditRepository.QueryAsync orders (CreatedAtUtc DESC, TrackedOperationId -- DESC), and its keyset predicate is exactly that pair. None of the existing -- SiteCalls indexes lead unconditionally on CreatedAtUtc: -- - IX_SiteCalls_Source_Created requires an equality on SourceSite first. -- - IX_SiteCalls_NonTerminal / IX_SiteCalls_Terminal are each filtered to one -- side of TerminalAtUtc. -- So an unfiltered (or lightly filtered) page fell back to a full clustered-index -- scan + sort. IX_SiteCalls_Created_TrackedOperationId (CreatedAtUtc DESC, -- TrackedOperationId DESC) makes a forward scan of the index deliver rows in the -- requested order directly, so a keyset page reads a Top-N off the index instead -- of sorting the whole table on every page request. -- -- SiteCalls is small enough today that a plain (offline) index build is fine. On -- an Enterprise edition instance where the table has grown large and the Central -- UI must stay responsive, add WITH (ONLINE = ON) to the CREATE INDEX below. -- -- Run with QUOTED_IDENTIFIER ON. Several tables in this database carry filtered -- indexes and persisted computed columns, and SQL Server refuses DDL/DML against -- them with error 1934 when the session has QUOTED_IDENTIFIER OFF -- which is -- exactly what `sqlcmd` gives you by default (pass -I, or keep this header). The -- SETs sit in their own batch so they are in force when the statements after the -- GO parse. SET QUOTED_IDENTIFIER ON; SET ANSI_NULLS ON; GO BEGIN TRANSACTION; IF NOT EXISTS ( SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20260819183326_AddSiteCallsListSortIndex' ) BEGIN EXEC(N'CREATE INDEX [IX_SiteCalls_Created_TrackedOperationId] ON [SiteCalls] ([CreatedAtUtc] DESC, [TrackedOperationId] DESC)'); END; IF NOT EXISTS ( SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20260819183326_AddSiteCallsListSortIndex' ) BEGIN INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) VALUES (N'20260819183326_AddSiteCallsListSortIndex', N'10.0.7'); END; COMMIT; GO