Indexing Anti-Patterns and Maintenance

Avoid over-indexing, duplicate indexes, low-value indexes, stale statistics, and maintenance mistakes.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Anti-patterns
Avoid duplicate or overlapping indexes
Potential overlap:
INDEX (user_id)
INDEX (user_id, created_at)

The second index may already cover many uses of the first.

# Do not keep several indexes that serve the same leading prefix needlessly.

Be careful with low-cardinality flags
-- Often weak by itself
INDEX (is_deleted)

-- Often better
INDEX (is_deleted, created_at)
-- or a partial index where supported

# A boolean by itself is often weak unless paired with something else or made partial.

Remember unused index cost
Every INSERT, UPDATE, and DELETE may need to update every relevant index.

# Unused indexes still hurt writes and consume disk.

## Maintenance tasks
PostgreSQL REINDEX
REINDEX INDEX idx_orders_user_id;

# Rebuild a problematic or bloated index.

MySQL ANALYZE TABLE
ANALYZE TABLE users;

# Refresh optimizer statistics after big data shifts.

SQLite VACUUM after major churn
VACUUM;

# Compact the file after heavy changes when appropriate.

Recommended next

No recommendations yet.