Measure and drop redundant AuditLogEntries single-column indexes #70

Open
opened 2026-11-06 15:24:45 -05:00 by dohertj2 · 4 comments
Owner

Register row 135 (deferred-work register).

ReviewRemediationIndexes added composite AuditLogEntries indexes (EntityType, Timestamp DESC), (User, Timestamp DESC), (Timestamp DESC, Id DESC); the older single-column timestamp/user/entity-type indexes may be dead weight on a write-heavy table.

Revisit trigger (from register): Measure sys.dm_db_index_usage_stats after a few weeks in QA, then drop unused ones via a migration.

Current state: The migration was applied on DEV vd03 and QA vq03/vq04 on 2026-10-22 (migrations 57 → 58; docs/deployment/deployment-records/2026-10-22-*.md), so the measurement clock started then. Index usage can be read with a direct SQL login (no remote exec needed).

Source: docs/plans/2026-07-08-deferred-work-register.md row 135

Register row 135 (deferred-work register). `ReviewRemediationIndexes` added composite `AuditLogEntries` indexes `(EntityType, Timestamp DESC)`, `(User, Timestamp DESC)`, `(Timestamp DESC, Id DESC)`; the older single-column timestamp/user/entity-type indexes may be dead weight on a write-heavy table. **Revisit trigger (from register):** Measure `sys.dm_db_index_usage_stats` after a few weeks in QA, then drop unused ones via a migration. **Current state:** The migration was applied on DEV vd03 and QA vq03/vq04 on 2026-10-22 (migrations 57 → 58; `docs/deployment/deployment-records/2026-10-22-*.md`), so the measurement clock started then. Index usage can be read with a direct SQL login (no remote exec needed). Source: `docs/plans/2026-07-08-deferred-work-register.md` row 135
dohertj2 added the type:debtpriority:p3migrated labels 2026-11-06 15:24:45 -05:00
Author
Owner

Tried to take the measurement on 2026-11-09 (18 days after the 2026-10-22 migration) with a direct, read-only SQL query. Blocked on access: the only SQL login available from the Mac (the Historian wonderapp-style login) cannot open the ScadaBridge database on either wonder-app-vd03 (DEV) or wonder-sql-vq03 (QA) — "Cannot open database ScadaBridge requested by the login". I did not pull the app's own connection string off the boxes.

To unblock: either grant a read-only login VIEW DATABASE STATE + CONNECT on ScadaBridge (QA first), or run this as the DBA and paste the output here:

SELECT sqlserver_start_time FROM sys.dm_os_sys_info;   -- usage stats reset on restart
SELECT i.name, i.type_desc,
       ISNULL(s.user_seeks,0) seeks, ISNULL(s.user_scans,0) scans,
       ISNULL(s.user_lookups,0) lookups, ISNULL(s.user_updates,0) updates,
       s.last_user_seek, s.last_user_scan
FROM sys.indexes i
LEFT JOIN sys.dm_db_index_usage_stats s
  ON s.object_id = i.object_id AND s.index_id = i.index_id AND s.database_id = DB_ID()
WHERE i.object_id = OBJECT_ID('dbo.AuditLogEntries')
ORDER BY i.index_id;

Decision rule once the numbers are in: a single-column index with 0 seeks/scans/lookups since the last restart and a restart older than ~2 weeks, whose leading column is covered by one of the ReviewRemediationIndexes composites, gets dropped in a migration (QA first). Adding blocked label.

Tried to take the measurement on 2026-11-09 (18 days after the 2026-10-22 migration) with a direct, read-only SQL query. **Blocked on access:** the only SQL login available from the Mac (the Historian `wonderapp`-style login) cannot open the `ScadaBridge` database on either `wonder-app-vd03` (DEV) or `wonder-sql-vq03` (QA) — "Cannot open database ScadaBridge requested by the login". I did not pull the app's own connection string off the boxes. To unblock: either grant a read-only login `VIEW DATABASE STATE` + `CONNECT` on `ScadaBridge` (QA first), or run this as the DBA and paste the output here: ```sql SELECT sqlserver_start_time FROM sys.dm_os_sys_info; -- usage stats reset on restart SELECT i.name, i.type_desc, ISNULL(s.user_seeks,0) seeks, ISNULL(s.user_scans,0) scans, ISNULL(s.user_lookups,0) lookups, ISNULL(s.user_updates,0) updates, s.last_user_seek, s.last_user_scan FROM sys.indexes i LEFT JOIN sys.dm_db_index_usage_stats s ON s.object_id = i.object_id AND s.index_id = i.index_id AND s.database_id = DB_ID() WHERE i.object_id = OBJECT_ID('dbo.AuditLogEntries') ORDER BY i.index_id; ``` Decision rule once the numbers are in: a single-column index with 0 seeks/scans/lookups since the last restart and a restart older than ~2 weeks, whose leading column is covered by one of the `ReviewRemediationIndexes` composites, gets dropped in a migration (QA first). Adding `blocked` label.
dohertj2 added the blocked label 2026-11-09 18:31:42 -05:00
Author
Owner

Measured 2026-11-13: no migration yet. The window is too short, and no index was read on either tier.

Read-only DMV query over a direct SQL login (sys.dm_db_index_usage_stats + sys.dm_db_index_operational_stats).

Tier DB sqlserver_start_time Window Rows
DEV vd03 / ScadaBridge (migr. 64) 2026-11-10 06:42 ~3 days 471
QA wonder-sql-vq03 / ScadaBridge (migr. 58) 2026-11-03 07:09 ~10 days 567
Index DEV seeks/scans/lookups (upd) QA seeks/scans/lookups (upd)
PK (Id) 0/0/0 (0) 0/0/0 (10)
Action / EntityId / BundleImportId 0/0/0 (0) 0/0/0 (10)
EntityType 0/0/0 (0) 0/0/0 (10)
Timestamp 0/0/0 (0) 0/0/0 (10)
User 0/0/0 (0) 0/0/0 (10)
EntityType,Timestamp DESC 0/0/0 (0) 0/0/0 (10)
Timestamp DESC,Id DESC 0/0/0 (0) 0/0/0 (10)
User,Timestamp DESC 0/0/0 (0) 0/0/0 (10)
EntityName (DEV only) 0/0/0 (0) —

Each single-column index is 72 KB. Each composite is 200 KB.

Decision. Both windows are under two weeks, because SQL restarts after the 2026-10-22 migration reset the counters. Every index reads zero, including the composites, so a zero on the old indexes proves nothing. In code, the three are left prefixes of the composites, and the CentralUiRepository filters/order and the ConfigAuditPurgeService range are all covered. So a drop is sound in principle, but it has not been measured yet. Write cost is negligible (~500 rows, ~1 insert/day on QA), so waiting costs nothing.

Re-measure on or after 2026-11-27. Check sqlserver_start_time first. If the composites show reads and the single-column indexes still show zero, drop Timestamp/User/EntityType (Down() recreates them). If everything is still zero, the owner decides: drop on static grounds, or exercise the config-audit page on QA first.

Evidence: docs/plans/2026-11-13-auditlogentries-index-usage.md (main bba3c348). The issue stays open and blocked on the re-measure.

**Measured 2026-11-13: no migration yet. The window is too short, and no index was read on either tier.** Read-only DMV query over a direct SQL login (`sys.dm_db_index_usage_stats` + `sys.dm_db_index_operational_stats`). | Tier | DB | `sqlserver_start_time` | Window | Rows | |---|---|---|---|---| | DEV | vd03 / ScadaBridge (migr. 64) | 2026-11-10 06:42 | ~3 days | 471 | | QA | wonder-sql-vq03 / ScadaBridge (migr. 58) | 2026-11-03 07:09 | ~10 days | 567 | | Index | DEV seeks/scans/lookups (upd) | QA seeks/scans/lookups (upd) | |---|---|---| | PK (Id) | 0/0/0 (0) | 0/0/0 (10) | | Action / EntityId / BundleImportId | 0/0/0 (0) | 0/0/0 (10) | | **EntityType** | 0/0/0 (0) | 0/0/0 (10) | | **Timestamp** | 0/0/0 (0) | 0/0/0 (10) | | **User** | 0/0/0 (0) | 0/0/0 (10) | | EntityType,Timestamp DESC | 0/0/0 (0) | 0/0/0 (10) | | Timestamp DESC,Id DESC | 0/0/0 (0) | 0/0/0 (10) | | User,Timestamp DESC | 0/0/0 (0) | 0/0/0 (10) | | EntityName (DEV only) | 0/0/0 (0) | — | Each single-column index is 72 KB. Each composite is 200 KB. **Decision.** Both windows are under two weeks, because SQL restarts after the 2026-10-22 migration reset the counters. Every index reads zero, *including the composites*, so a zero on the old indexes proves nothing. In code, the three are left prefixes of the composites, and the `CentralUiRepository` filters/order and the `ConfigAuditPurgeService` range are all covered. So a drop is sound in principle, but it has not been measured yet. Write cost is negligible (~500 rows, ~1 insert/day on QA), so waiting costs nothing. **Re-measure on or after 2026-11-27.** Check `sqlserver_start_time` first. If the composites show reads and the single-column indexes still show zero, drop `Timestamp`/`User`/`EntityType` (Down() recreates them). If everything is still zero, the owner decides: drop on static grounds, or exercise the config-audit page on QA first. Evidence: `docs/plans/2026-11-13-auditlogentries-index-usage.md` (main `bba3c348`). The issue stays open and `blocked` on the re-measure.
dohertj2 added the due date 2026-11-27 2026-11-15 16:58:12 -05:00
Author
Owner

Reminder set: re-measure on 2026-11-27 (issue due date). Steps: (1) check sqlserver_start_time on vd03 and wonder-sql-vq03 — a restart since the last read resets the window; (2) re-run the DMV query from the 2026-11-09 comment; (3) apply the decision rule from the 2026-11-13 comment (composites read and single-column still zero → drop Timestamp/User/EntityType, QA first; all zero → owner decides).

**Reminder set: re-measure on 2026-11-27** (issue due date). Steps: (1) check `sqlserver_start_time` on vd03 and wonder-sql-vq03 — a restart since the last read resets the window; (2) re-run the DMV query from the 2026-11-09 comment; (3) apply the decision rule from the 2026-11-13 comment (composites read and single-column still zero → drop `Timestamp`/`User`/`EntityType`, QA first; all zero → owner decides).
Author
Owner

Re-measured 2026-12-02 on QA. No migration: the drop rule is not met, and the result points the other way.

Read-only query of sys.dm_db_index_usage_stats over a direct SQL login on wonder-sql-vq03 / ScadaBridge. No WinRM.

  • Window: sqlserver_start_time is 2026-11-03 07:09, so the window is ~29 days, past the two-week minimum.
  • Latest migration: 20261115221558_RemoveAuditLogHashChain.
  • Table: 730 rows. The newest row is from 2026-11-30.
Index Seeks Scans Lookups Last scan
PK_AuditLogEntries (clustered) 0 2 3 2026-11-28
IX_AuditLogEntries_Action 0 0 0 —
IX_AuditLogEntries_EntityId 0 0 0 —
IX_AuditLogEntries_EntityType 0 1 0 2026-11-20
IX_AuditLogEntries_Timestamp 0 2 ¹ 0 — ¹
IX_AuditLogEntries_User 0 0 0 —
IX_AuditLogEntries_BundleImportId 0 1 0 2026-11-24
IX_AuditLogEntries_EntityType_Timestamp 0 0 0 —
IX_AuditLogEntries_Timestamp_Id 0 0 0 —
IX_AuditLogEntries_User_Timestamp 0 0 0 —
IX_AuditLogEntries_EntityName 1 1 0 2026-11-20

Every index shows 160 updates (150 for EntityName).

¹ The DMV shows 3 scans. The third is the measurement query itself (COUNT/MAX(Timestamp) at 13:23:10), so it is left out. The DMV keeps only the latest scan time, so the date of the earlier scans is unknown.

Reading. The config-audit page was used during the window (filtered reads on 2026-11-20). When it was, the optimizer read the old single-column EntityType and Timestamp indexes, and none of the three composites was read. The rule from 2026-11-13 says to drop only if the composites show reads and the single-column indexes show none. QA shows the reverse, so the rule is not met.

Dropping them would still be safe in function, because each single-column index is a left prefix of a composite. But the measurement doesn't back it, and it would save only about 216 KB and 3 index writes per audit row. At 730 rows these plan choices say little about how a large table would behave.

Recommendation: close as won't-fix. The single-column indexes are in use and cost almost nothing. Owner to decide. DEV vd03 was not re-measured.

**Re-measured 2026-12-02 on QA. No migration: the drop rule is not met, and the result points the other way.** Read-only query of `sys.dm_db_index_usage_stats` over a direct SQL login on `wonder-sql-vq03` / `ScadaBridge`. No WinRM. - Window: `sqlserver_start_time` is 2026-11-03 07:09, so the window is **~29 days**, past the two-week minimum. - Latest migration: `20261115221558_RemoveAuditLogHashChain`. - Table: 730 rows. The newest row is from 2026-11-30. | Index | Seeks | Scans | Lookups | Last scan | |---|---|---|---|---| | PK_AuditLogEntries (clustered) | 0 | 2 | 3 | 2026-11-28 | | IX_AuditLogEntries_Action | 0 | 0 | 0 | — | | IX_AuditLogEntries_EntityId | 0 | 0 | 0 | — | | **IX_AuditLogEntries_EntityType** | 0 | **1** | 0 | 2026-11-20 | | **IX_AuditLogEntries_Timestamp** | 0 | **2** ¹ | 0 | — ¹ | | **IX_AuditLogEntries_User** | 0 | 0 | 0 | — | | IX_AuditLogEntries_BundleImportId | 0 | 1 | 0 | 2026-11-24 | | IX_AuditLogEntries_EntityType_Timestamp | 0 | 0 | 0 | — | | IX_AuditLogEntries_Timestamp_Id | 0 | 0 | 0 | — | | IX_AuditLogEntries_User_Timestamp | 0 | 0 | 0 | — | | IX_AuditLogEntries_EntityName | 1 | 1 | 0 | 2026-11-20 | Every index shows 160 updates (150 for EntityName). ¹ The DMV shows 3 scans. The third is the measurement query itself (`COUNT`/`MAX(Timestamp)` at 13:23:10), so it is left out. The DMV keeps only the latest scan time, so the date of the earlier scans is unknown. **Reading.** The config-audit page was used during the window (filtered reads on 2026-11-20). When it was, the optimizer read the **old single-column** `EntityType` and `Timestamp` indexes, and **none of the three composites was read**. The rule from 2026-11-13 says to drop only if the composites show reads and the single-column indexes show none. QA shows the reverse, so the rule is not met. Dropping them would still be safe in function, because each single-column index is a left prefix of a composite. But the measurement doesn't back it, and it would save only about 216 KB and 3 index writes per audit row. At 730 rows these plan choices say little about how a large table would behave. **Recommendation:** close as won't-fix. The single-column indexes are in use and cost almost nothing. Owner to decide. DEV vd03 was not re-measured.
Sign in to join this conversation.