9a574746dc
Adds IX_AuditLog_Channel_Occurred (Category, OccurredAtUtc) ON ps_AuditLog_Month(OccurredAtUtc) via raw SQL (EF CreateIndex cannot express the partition scheme), like ReviewRemediationIndexes. Idempotent QA/DEV script: docs/plans/sql/AuditLogChannelOccurredIndex.sql (sqlcmd -I). Kept in its own commit so the integrator can regenerate it on merge with the other WPs' migrations. Index-name pins updated: AuditLogEntityTypeConfigurationTests and FlipAuditLogClusteredKeyMigrationTests (head shape asserts the new index is partition-aligned on ps_AuditLog_Month; the pre-flip round-trip shape does not carry it).
40 lines
1.5 KiB
Transact-SQL
40 lines
1.5 KiB
Transact-SQL
-- AuditLogChannelOccurredIndex (2026-12-03, WP6 task 6.5 / review finding AUD-5). Run with
|
|
-- QUOTED_IDENTIFIER ON (sqlcmd -I, or keep this header): AuditLog has persisted computed
|
|
-- columns / filtered indexes and SQL Server raises error 1934 otherwise.
|
|
-- Adds IX_AuditLog_Channel_Occurred (Category, OccurredAtUtc) for the per-channel retention
|
|
-- purge. AuditLog is monthly-partitioned; the index is created ON ps_AuditLog_Month(OccurredAtUtc)
|
|
-- so it stays partition-aligned and the partition-switch purge keeps working. Building it scans
|
|
-- the whole AuditLog: on a large production table run in a quiet window, and on Enterprise
|
|
-- edition add WITH (ONLINE = ON) to the CREATE INDEX statement.
|
|
-- Ships with the binaries that bind the purge's @channel parameter as varchar(32); either order
|
|
-- is safe (the index only helps; the old binaries' nvarchar binding simply cannot seek it).
|
|
SET QUOTED_IDENTIFIER ON;
|
|
SET ANSI_NULLS ON;
|
|
GO
|
|
|
|
BEGIN TRANSACTION;
|
|
IF NOT EXISTS (
|
|
SELECT * FROM [__EFMigrationsHistory]
|
|
WHERE [MigrationId] = N'20261203152558_AuditLogChannelOccurredIndex'
|
|
)
|
|
BEGIN
|
|
|
|
CREATE NONCLUSTERED INDEX IX_AuditLog_Channel_Occurred
|
|
ON dbo.AuditLog (Category, OccurredAtUtc)
|
|
ON ps_AuditLog_Month(OccurredAtUtc);
|
|
END;
|
|
|
|
IF NOT EXISTS (
|
|
SELECT * FROM [__EFMigrationsHistory]
|
|
WHERE [MigrationId] = N'20261203152558_AuditLogChannelOccurredIndex'
|
|
)
|
|
BEGIN
|
|
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
|
|
VALUES (N'20261203152558_AuditLogChannelOccurredIndex', N'10.0.13');
|
|
END;
|
|
|
|
COMMIT;
|
|
GO
|
|
|
|
|