Why Database Monitors Cry Wolf: 7 Evidence Rules We Enforce in Rust
Dropping an index that a read replica relies on or indexing a 40%-selective column makes production slower. Seven anti-false-flag rules we hardcoded into Culprit's Rust check pipeline so alerts stay trustworthy.
Almost every DBA has a folder of DMV scripts, and almost every application developer has been burned by taking one of those scripts too literally.
You run a popular “Top Missing Indexes” query on SQL Server, add the three indexes with the highest avg_user_impact, and watch write latency double while select queries barely move. Or a dashboard flags an index with user_seeks = 0 on the primary, someone drops it on Friday afternoon, and Monday’s billing batch grinds to a halt on the readable secondary.
When we started building Culprit SQL Studio and its ADX / ClickHouse warehouse synthesizer, our top architectural goal was simple: a finding must never be a false flag. If the evidence cannot prove a claim, stay quiet and explain what measurement is missing.
Here are the seven rules enforced in crates/culprit-checks before any finding is allowed to render.
1. Never call an index “unused” without every read replica and 7 days of counters
sys.dm_db_index_usage_stats and pg_stat_user_indexes reset to zero whenever the engine restarts, fails over, or Detach/Attaches a database. Even worse, index usage counters are local to the instance that executed the query.
An index created specifically for BI reporting or customer CSV exports on an Availability Group readable secondary (or RDS read replica) will legitimately show 0 seeks and 0 scans on the primary forever, while still paying write maintenance on every INSERT and UPDATE.
Culprit refuses to emit unused-index unless two conditions hold simultaneously:
- Counter uptime spans at least 7 full days without an intervening reset.
- Either the database is a standalone single-node topology, or index usage has been attested across
AllReadMembers(primary + all read replicas). Otherwise, the check locks and states that replica usage is unverified.
2. Never recommend an index that keeps more than 10% of the table
Database engines love asking for indexes they should not have. SQL Server’s <MissingIndexes> XML group only sees the single query being compiled; it cheerfully asks for a wide nonclustered index on WHERE archived = 0 when 92% of the table has archived = 0.
In Culprit, every index recommendation must pass INDEX_KEEPS_AT_MOST (10% selectivity), verified against row counts and column statistics (sys.dm_db_stats_histogram / pg_stats). If a predicate keeps 40% of a table, adding a B-tree index wastes disk, slows writes, and usually gets ignored by the optimizer anyway.
3. Separate column-side CONVERT_IMPLICIT from harmless parameter casts
Many plan analyzers grep .sqlplan XML for the substring CONVERT_IMPLICIT and throw a red warning every time it appears. That produces constant false alarms.
If a column is bigint and your ORM binds @p0 as int, SQL Server widens @p0 once before seeking the index (CONVERT_IMPLICIT(bigint, [@p0], 0)). That seek is 4 logical reads and completely SARGable.
The real killer is column-side conversion (converts_column): when a varchar(64) column is compared against an nvarchar(64) parameter (N'ch_3Q91...'). Because nvarchar has higher data-type precedence than varchar, SQL Server must run CONVERT_IMPLICIT(nvarchar(64), [external_ref], 0) on every row in the index, turning a 4-page seek into a 19,420-page scan:
Culprit parses the scalar expression AST inside <SeekPredicates> and <Predicate> and only flags implicit-conversion when the table column itself is wrapped in the cast.
4. Never extrapolate 5 minutes of traffic into “per day”, and never turn None into 0
If you attach to a database whose counters reset twenty minutes ago during a deploy, multiplying 20 minutes of page splits by 72 and telling the user “430,000 splits/day” is fiction.
All rate math in Culprit flows through one shared helper (support::rate_per_day and counter_rate_per_day):
- Under 1 hour of counter history, no rate is computed at all.
- Between 1 hour and 20 hours, rates are expressed strictly over the observed window, never extrapolated to “a day”.
- On engines with cumulative totals and no native window (like
pg_stat_statements), rates are computed across deltas between Culprit’s own verified scans (Workload::over_scans), rejecting any pair wherestats_resetor server incarnation changed. - And across every provider struct, an unmeasured metric is
Option::None, never0.
5. Trust the engine’s runtime verdict over guessing from plan shape
Static plan linters often flag every Seq Scan or Hash Match as bad. On a 400-row lookup table (or a reporting query joining 80% of two tables), a sequential scan + hash join is the fastest plan the hardware can execute.
Whenever actual runtime counters or Query Store wait evidence exist, Culprit checks what the engine actually suffered: measured SpillToTempDb warnings, actual vs estimated row skew causing memory-grant starvation (RESOURCE_SEMAPHORE), or measured logical reads per row returned. A small table scan that took 0.3 ms never pollutes your findings list.
6. One cause produces one finding (refine.rs)
Without cross-finding refinement, one underlying mistake triggers five overlapping complaints:
- Query A shows up as
heavy-query,key-lookup,missing-index, andhigh-io. - One
idle in transactionsession blocks 40 workers, generating 40 separate lock warnings (which is why standard alert rules page on victims). - A migration query that ran once six hours ago and finished dominates
mean_exec_time.
Culprit’s pipeline runs prepare -> detect -> refine -> rank. The refine stage collapses duplicate symptoms onto the single actionable root cause, walks blocking chains to the head blocker, and demotes one-off historical queries so your top finding is something still hurting you right now.
Plugging in your own checks
Because every built-in check implements the public culprit_core::Check trait over an immutable Snapshot, you can embed custom company rules via Workspace::with_check(Arc::new(MyCheck)) and get the exact same refinement, ranking, redaction, and warehouse synthesis pipeline automatically. See docs/ARCHITECTURE.md for the full pipeline contract.
Database Hub in Microsoft Fabric is now GA as Microsoft's replacement for Azure SQL Database Watcher. I put its Fabric Capacity Unit math, Power BI Pro viewer cliff, and portal charts next to running Culprit on your own ADX or ClickHouse cluster.