-- arch-review 2026-08-19 P5-3 (register row-35 class): the Notifications list -- page's sort key gets its own index. -- -- NotificationOutboxRepository.QueryAsync orders (CreatedAt DESC, NotificationId -- DESC) (NotificationId breaks CreatedAt ties for deterministic OFFSET paging). -- None of the existing Notifications indexes lead unconditionally on CreatedAt: -- - IX_Notifications_Status_NextAttemptAt requires an equality on Status first. -- - IX_Notifications_SourceSiteId_CreatedAt requires an equality on SourceSiteId first. -- - IX_Notifications_Delivered is filtered to Status = 'Delivered' only. -- So an unfiltered (or lightly filtered) page fell back to a full clustered-index -- scan + sort. IX_Notifications_Created_NotificationId (CreatedAt DESC, -- NotificationId DESC) makes a forward scan of the index deliver rows in the -- requested order directly, so a page reads a Top-N off the index instead of -- sorting the whole table on every COUNT + page request. -- -- Notifications 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'20260819201210_AddNotificationsListSortIndex' ) BEGIN EXEC(N'CREATE INDEX [IX_Notifications_Created_NotificationId] ON [Notifications] ([CreatedAt] DESC, [NotificationId] DESC)'); END; IF NOT EXISTS ( SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'20260819201210_AddNotificationsListSortIndex' ) BEGIN INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) VALUES (N'20260819201210_AddNotificationsListSortIndex', N'10.0.7'); END; COMMIT; GO