perf(central): set-based ingest, aligned partition purge, KPI query shapes, EF hygiene

This commit is contained in:
Joseph Doherty
2026-08-14 21:07:12 -04:00
parent ee193cd2bb
commit 5db2a810c0
29 changed files with 3790 additions and 266 deletions
@@ -85,22 +85,27 @@ public class AddAuditLogTableMigrationTests : IClassFixture<MsSqlMigrationFixtur
}
/// <summary>
/// Verifies all nine named non-clustered indexes exist on the final
/// <c>dbo.AuditLog</c> table after all migrations have been applied.
/// Verifies all eight named non-clustered indexes exist on the final
/// <c>dbo.AuditLog</c> table after all migrations have been applied, and that
/// the non-aligned <c>UX_AuditLog_EventId</c> does NOT.
/// The original five indexes were created by <c>AddAuditLogTable</c>;
/// the <c>CollapseAuditLogToCanonical</c> (C5, Task 2.5) migration rebuilt
/// the table and added <c>IX_AuditLog_Execution</c>,
/// <c>IX_AuditLog_ParentExecution</c>, <c>IX_AuditLog_Node_Occurred</c>,
/// and <c>UX_AuditLog_EventId</c> — nine in total.
/// <c>IX_AuditLog_ParentExecution</c> and <c>IX_AuditLog_Node_Occurred</c>.
/// <c>UX_AuditLog_EventId</c> was created alongside them but dropped again by
/// <c>AlignAuditLogEventIdUniqueness</c> (WP2.2) — its non-alignment forced an
/// offline drop/rebuild around every partition-switch purge, and the clustered
/// <c>PK_AuditLog (EventId, OccurredAtUtc)</c> already enforces the same
/// uniqueness partition-aligned.
/// </summary>
[SkippableFact]
public async Task AppliesMigration_CreatesNineNamedIndexes()
public async Task AppliesMigration_CreatesEightNamedIndexes_AndNoNonAlignedUniqueIndex()
{
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
// All nine named non-clustered indexes present on dbo.AuditLog after
// All eight named non-clustered indexes present on dbo.AuditLog after
// the full migration history is applied (AddAuditLogTable through
// CollapseAuditLogToCanonical).
// AlignAuditLogEventIdUniqueness).
var expected = new[]
{
// Original five (AddAuditLogTable / AddAuditLogSourceNode):
@@ -113,7 +118,6 @@ public class AddAuditLogTableMigrationTests : IClassFixture<MsSqlMigrationFixtur
"IX_AuditLog_Execution",
"IX_AuditLog_ParentExecution",
"IX_AuditLog_Node_Occurred",
"UX_AuditLog_EventId",
};
foreach (var indexName in expected)
@@ -124,6 +128,16 @@ public class AddAuditLogTableMigrationTests : IClassFixture<MsSqlMigrationFixtur
$"WHERE o.name = 'AuditLog' AND i.name = '{indexName}';");
Assert.True(count == 1, $"Expected index '{indexName}' to exist on AuditLog; found {count}.");
}
var nonAligned = await ScalarAsync<int>(
"SELECT COUNT(*) FROM sys.indexes i " +
"INNER JOIN sys.objects o ON i.object_id = o.object_id " +
"WHERE o.name = 'AuditLog' AND i.name = 'UX_AuditLog_EventId';");
Assert.True(
nonAligned == 0,
"UX_AuditLog_EventId must NOT exist after AlignAuditLogEventIdUniqueness — "
+ "a non-aligned index blocks ALTER TABLE ... SWITCH PARTITION and reinstates "
+ $"the offline drop/rebuild the purge path was freed from; found {nonAligned}.");
}
[SkippableFact]