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.

>= 7 days Minimum counter uptime + replica scope required before flagging unused indexes
<= 10% rows Selectivity ceiling (INDEX_KEEPS_AT_MOST) required for missing-index advice
>= 20 hours Observation span required before phrasing any rate as 'per day'

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:

Live .sqlplan diffClick any operator or switch Diagram / Tree
Open in Culprit Explain ↗
A nvarchar(64) param (19.4K page scan)vsB varchar(64) param (4-page seek)

48× fastervarchar(64) param (4-page seek) took 48× less time because it seeks ix_charges_external_ref where nvarchar(64) param (19.4K page scan) scans charges (100% of nvarchar(64) param (19.4K page scan)'s cost).

8.940
cost · nvarchar(64) param (19.4K page scan)
0.003
cost · varchar(64) param (4-page seek)
96 ms
time · nvarchar(64) param (19.4K page scan)
2 ms
time · varchar(64) param (4-page seek)
1 → 1
operators
0
identical regions
Anvarchar(64) param (19.4K page scan)SQL Server · actual
Actual plan1 operator · cost 8.94 1 plan warning80%
Measured run96 ms91 msCPU19Kreads1row
Where the 96 ms went
result
Bvarchar(64) param (4-page seek)SQL Server · actual
Actual plan1 operator · cost 0.00380%
Measured run2 ms1 msCPU4reads1row
Where the 2 ms went
result
Live @culpritsql/plan-viewer diff: sending an nvarchar(64) ORM parameter against a varchar(64) column forces CONVERT_IMPLICIT on the table column (19,420 logical reads across 1.25M rows vs 4 logical reads once the parameter type matches).

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 where stats_reset or server incarnation changed.
  • And across every provider struct, an unmeasured metric is Option::None, never 0.

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, and high-io.
  • One idle in transaction session 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.