Quick revision
The short answer
I would say no to the blanket rule, because every index costs write amplification, WAL volume, buffer pool memory, vacuum work and backup size, and many single-column indexes can make writes on a hot table several times slower while serving combined filters worse than one good composite index. Instead I would propose a workload-driven standard: index from real query statistics, review new indexes in migrations with a checklist, track and drop unused indexes, and detect duplicates automatically.
What to remember
In this answer, we saw why 'one single-column index for every filtered column' is a poor standard: each index adds write amplification, WAL, buffer pool pressure, vacuum work and backup size, and blocks HOT updates on frequently updated columns, while one well-ordered composite index usually serves combined filters better than a bitmap AND of single ones. The better standard indexes from real query statistics, reviews every index in migrations with a checklist, tracks unused indexes through idx_scan, and detects duplicates and prefixes automatically.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would say no to the blanket rule, because every index costs write amplification, WAL volume, buffer pool memory, vacuum work and backup size, and many single-column indexes can make writes on a hot table several times slower while serving combined filters worse than one good composite index. Instead I would propose a workload-driven standard: index from real query statistics, review new indexes in migrations with a checklist, track and drop unused indexes, and detect duplicates automatically.
Background to this question
A rule like 'index every column in a WHERE clause' comes from good intentions: a team was hurt by slow queries and wants to never be hurt again. But indexes are not free, and the cost appears somewhere else, on writes, replicas and the bill. As the database lead for 30 services, the job is to replace a simple rule that is wrong with a simple process that is right. In this answer, we will look at what each index costs, why composite indexes usually beat many single-column ones, and then write the standard, the review checklist and the automation.
1What Every Index Costs
An index is a second copy of some columns, kept in sorted order and updated on every write. An INSERT into a table with 12 indexes writes the row and 12 index entries. Each of those writes produces WAL, the write-ahead log that also feeds replicas and backups, so WAL volume and replica lag grow with the index count. Index pages compete with table pages for the buffer pool, so more indexes mean fewer of the hot pages fit in memory. Vacuum must clean every index, so maintenance takes longer. Backups and restores grow too.
PostgreSQL adds a less obvious cost. An update can be a HOT update, a heap-only tuple update that skips index maintenance entirely, only if no indexed column changes and the page has room. Indexing a column that is updated often, such as status or updated_at, turns cheap HOT updates into full updates of every index. On a hot table with dozens of single-column indexes, write throughput falling to a third or less is a realistic outcome.
| Indexes on the table | Pages modified per insert | Relative WAL | HOT updates possible |
|---|---|---|---|
| 2 (primary key + 1) | about 3 | 1x | often |
| 6 | about 7 | about 2x | rarely |
| 20 (one per filtered column) | about 21 | about 6x | almost never |
2Why One Composite Index Often Beats Many Single Ones
Most real queries filter on several columns at once: a customer's orders with a given status, sorted by date. With three single-column indexes, the database can combine them with a bitmap AND, scanning each index separately, building bitmaps of matching pages, intersecting them and then visiting the table. That works, but it reads three indexes and cannot return rows in sorted order. A single composite index on (customer_id, status, created_at) answers the same query with one descent to exactly the right entries, already in date order, and can stop after the LIMIT.
And the composite index also serves queries that filter only on customer_id, or on customer_id and status, because those are its leading columns. So one index replaces several, while serving the combined query better.
3The Standard: Index From the Workload
Instead of indexing every column, we index for the queries that actually run. pg_stat_statements in PostgreSQL, and the statement digests in MySQL's performance_schema, show which normalised queries consume the most total time and how often each runs. Each team reviews its top queries per service, and indexes are added to serve those queries, with the plan before and after attached to the change.
Every new index arrives through a schema migration, and migrations are reviewed like code. Unused indexes are tracked: pg_stat_user_indexes.idx_scan counts how often each index was used since statistics were last reset, and an index that stays at zero for a full release cycle, including month-end jobs, is a candidate to drop.
4The Review Checklist
A reviewer asks the same few questions of every new index. What query does it serve, and how selective is the condition, meaning what share of rows will it match? Is the column order right, with equality columns first and the range or sort column last? Could it be covering, with INCLUDE columns, to avoid table visits for a hot query? How write-heavy is the table, and does the index touch a frequently updated column that would block HOT updates? Does an existing index already serve it, or could an existing index be extended instead? And what is the plan to drop it if it stays unused for a release cycle?
- Name the query and attach its planfrom pg_stat_statements top list
- Does an existing index already serve it?YesReject or extend that indexNoContinue
- Is the table write-heavy or the column often updated?YesMeasure write cost firstNoContinue
- Choose column order and INCLUDE columnsequality first, then range or sort
- Merge with a drop planremove if unused for a release cycle
5 steps in order. Play them, or step through them one at a time.
5Automating Duplicate and Unused Index Detection
People will not catch every redundant index by reading migrations, so we automate it. A weekly job or a CI check lists indexes that are exact duplicates, indexes whose columns are a leading prefix of another index on the same table, and indexes with zero scans for 30 days.
The report goes to the owning team, not to a central queue, so the people who know the queries decide. Unique and primary key indexes are excluded because they enforce rules even when no query uses them for reading.
6Follow-up questions
How would you safely drop an index you believe is unused?
First confirm over a full business cycle, including month-end and quarter-end jobs, and on every replica, because idx_scan is counted per server and reads on replicas do not show on the primary. Check that it does not enforce a unique or exclusion constraint. In MySQL 8, make it invisible first with ALTER TABLE ... ALTER INDEX ... INVISIBLE, so the optimizer ignores it while it is still maintained, and make it visible again instantly if a query regresses. PostgreSQL has no invisible indexes, so we save its definition from pg_indexes, drop it with DROP INDEX CONCURRENTLY to avoid blocking writes, watch latency dashboards, and recreate it with CREATE INDEX CONCURRENTLY if needed.
Are there columns that should almost always be indexed?
Foreign key columns on the child side usually should be, because deletes and updates on the parent and joins from parent to child search them. PostgreSQL does not create these indexes automatically, unlike InnoDB, which requires an index for each foreign key.
What if a team really has many different filter combinations?
That is often a search or reporting workload, such as an admin screen with ten optional filters. It may be better served by a search engine, a read replica with its own indexes, or a few broad indexes plus accepting some scans, rather than an index per combination on the OLTP primary.
7Conclusion
In this answer, we saw why 'one single-column index for every filtered column' is a poor standard: each index adds write amplification, WAL, buffer pool pressure, vacuum work and backup size, and blocks HOT updates on frequently updated columns, while one well-ordered composite index usually serves combined filters better than a bitmap AND of single ones. The better standard indexes from real query statistics, reviews every index in migrations with a checklist, tracks unused indexes through idx_scan, and detects duplicates and prefixes automatically.
Open with
I would push back on the rule, while taking the underlying problem seriously. Every index is a cost on writes: each insert or update has to maintain it, which means more WAL, more replica lag, more buffer pool memory, more vacuum work and bigger backups.
Then, if they want more
In PostgreSQL, indexing a frequently updated column also prevents HOT updates. On a hot table with dozens of single-column indexes, writes can easily get several times slower.
And most queries filter on combinations of columns, where one composite index in the right order, equality columns first and the sort column last, answers the query with one descent and no sort, whereas single-column indexes need a bitmap AND and a sort. So I would propose a workload-driven standard.
Indexes come from real query statistics, pg_stat_statements or performance_schema digests, and every new index goes through a schema migration review with a checklist: which query, selectivity, column order, covering columns, write rate of the table, and a plan to drop it if it stays unused for a release cycle.
We track unused indexes with pg_stat_user_indexes.idx_scan, checked on replicas too, and a weekly automated report finds duplicates and prefixes of other indexes, sent to the owning team.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- MySQL 8
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A team wants a policy that every column used in any WHERE clause gets its own...": https://scrivio-interview-library.netlify.app/databases/indexing/60486e8f0c/