aja/workspace/engineering notes

IST --:--:--
engineering-notes

Selecting Database Indexes

21 Jul 2025·
DatabaseSQLPerformance

01Problem

Index sprawl: years of 'add an index, ship it' left tables with a dozen indexes each — write costs climbing, storage growing, and nobody sure which indexes were load-bearing.

02Context

Every index is a bet that read savings outweigh write costs. Nobody had been settling those bets: usage stats showed indexes unused for months still being maintained on every insert.

03Solution

A quarterly index review driven by the database's own statistics: rank indexes by reads vs writes, flag never-read indexes for staged removal (disable first, drop after a clean cycle), and require new indexes to name the query they serve in the migration description.

04Tradeoffs

Dropping an index is scarier than adding one — the failure mode is a slow query at peak, not a failed deploy. Staged disabling makes the bet reversible and cheap to lose.

05Outcome

Write-heavy tables shed a third of their indexes with no read regressions, and new indexes now arrive with a stated purpose that can be audited later.

06Lessons Learned

An index without a named query is a rumor, not a design decision.

The database keeps score of every bet you made — read the stats.