Group
  • Database

    Find and drop indexes my app never uses

    Uses database statistics to find indexes with zero or near-zero reads and removes them to speed up writes.

    • Debug & fix
    • Improve quality
    • Intermediate
    • General

Free Prompt

Audit my database for unused and redundant indexes and remove the ones that are only slowing down writes. 1. Find unused indexes: query the database's index usage statistics (pg_stat_user_indexes for Postgres, the equivalent for MySQL or my ORM's introspection tools) and list every index with zero or near-zero scans since the stats were last reset. 2. Find redundant indexes: identify indexes that are fully covered by another index (an index on (a) is redundant if one on (a, b) exists, since the composite can serve queries on a alone) and duplicate indexes created twice under different names. 3. Verify before dropping: for each candidate, check my actual query patterns first. Confirm no query in the codebase filters or joins on those columns in a way that would lose its index, and rule out indexes that only serve rare-but-important queries (nightly jobs, admin reports) before removing them. Also confirm the index is not enforcing a constraint (unique indexes stay). 4. Drop safely: write the migration to drop the confirmed-dead indexes concurrently where the database supports it, so the drop itself does not lock the table. Do not drop unique indexes or indexes backing foreign keys without flagging them separately. Do not trust stats alone if the database was restarted recently; tell me how old the stats are. Give me a table: index name, size, scan count, verdict (drop, keep, investigate), and why. Then the migration for the drops.

What This Does / How This Helps

Uses the database's own statistics to find indexes nobody reads and removes them, making every write cheaper. Indexes are not free. Every insert and update maintains every index on the table, and they eat RAM that could be caching useful data. AI assistants add indexes liberally, one per plausible column, and nobody goes back to check whether any query actually uses them. Write-heavy tables end up paying for five indexes to serve one. The prompt reads real usage stats, cross-checks against your actual queries so nothing important gets dropped, and writes a safe concurrent-drop migration with a clear keep/drop verdict per index.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts