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

Mistakes that waste storage and slow writes without helping queries much.

Avoid duplicate or overlapping indexes

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

sqlANYduplicate-indexoverlap
sql
Potential overlap:
INDEX (user_id)
INDEX (user_id, created_at)

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

Review actual query patterns before keeping both. Some overlap is justified, but not all of it.

Be careful with low-cardinality flags

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

sqlANYcardinalityflags
sql
-- Often weak by itself
INDEX (is_deleted)

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

A low-cardinality flag alone may still leave too much work for the engine.

Remember unused index cost

Unused indexes still hurt writes and consume disk.

textANYwrite-overheadstorage
text
Every INSERT, UPDATE, and DELETE may need to update every relevant index.

Unused indexes are not free and should be reviewed periodically.

Maintenance tasks

Housekeeping that keeps planners and indexes healthy.

PostgreSQL REINDEX

Rebuild a problematic or bloated index.

sqlANYpostgresqlreindex
sql
REINDEX INDEX idx_orders_user_id;

Use with care and pair with engine-specific operational guidance in production.

MySQL ANALYZE TABLE

Refresh optimizer statistics after big data shifts.

sqlANYmysqlstatistics
sql
ANALYZE TABLE users;

Statistics help the optimizer estimate row counts more accurately.

SQLite VACUUM after major churn

Compact the file after heavy changes when appropriate.

sqlANYsqlitevacuum
sql
VACUUM;

Not an index command specifically, but often relevant for long-lived local databases after large deletions or churn.

Recommended next

No recommendations yet.