(Note · · 6 min read)
Adding indexes did not make it faster
Someone adds an index to every column in the slow query and nothing improves. Indexes are not a dial for making a database faster — each one answers a specific shape of question, and an index the planner cannot use is pure cost.
By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka
Read the plan before changing anything
Every database will tell you how it intends to run a query and, with the right option, what actually happened. That output is the only reliable guide: it names which index was used, how many rows were examined against how many were returned, and where the time went.
The signal to look for is a large gap between rows examined and rows returned. That is work being done to throw data away, and it is what an index removes. A sequential scan on a small table is not a problem and needs no index.
Column order is the whole game
In a multi-column index the order decides which queries can use it. An index on tenant and then date serves a query filtering on tenant, and a query filtering on tenant and date, but not one filtering on date alone.
The usual rule: equality conditions first, then the range or sort column. Getting this right often means one index serves several queries, where the wrong order means three indexes and none of them used.
Index the query, not the column
Decide from the queries the application actually runs, which means knowing them. The slow query log is the input to this, not intuition about which columns look important.
- An index cannot be used if the column is wrapped in a function — index the expression instead, or stop wrapping it.
- A leading wildcard search cannot use an ordinary index; that needs a text search index or a different approach.
- Where only a fraction of rows are ever queried — active records, pending jobs — a partial index on that subset is much smaller and faster.
- If an index contains every column a query needs, the database can answer from the index alone and never touch the table.
- Mismatched types between the column and the parameter can prevent an index being used at all.
Every index costs something
Indexes have to be kept current on every insert, update and delete, and they occupy space and memory. A table with a dozen speculative indexes writes measurably slower, and the planner has more options to consider on every query.
Most databases record how often each index is used. Look for the ones with no reads and drop them — they are paying the write cost and returning nothing. Also look for indexes that are a prefix of another, which are usually redundant.
Create them without locking the table
On a large table, building an index the ordinary way blocks writes for as long as it takes. Use the concurrent variant your database offers; it is slower and has conditions, and it is the difference between a deploy and an outage.
Measure with real data volumes
A plan chosen against a thousand rows tells you little about the plan chosen against ten million, because the planner's choices depend on the statistics. Test against a restored copy of production, and make sure statistics are current before concluding anything.
Then confirm under concurrency. Indexing work on the payroll platform is part of what moved p95 response at 50 concurrent users from 1.9 seconds to 207 milliseconds in a laptop benchmark with 10,000 seeded employees and 420,000 attendance records, dated 16 November 2026 — a figure that only appears when more than one request is in flight.
Common questions
How do I know which index to add?
Read the query plan. It names the index used and shows rows examined against rows returned; a large gap between them is work spent discarding data, which is what an index removes. Decide from the queries the application actually runs, not from which columns look important.
Does column order matter in a composite index?
It decides which queries can use it. An index on tenant then date serves filters on tenant, and on tenant with date, but not on date alone. Put equality conditions first, then the range or sort column.
Why is my index being ignored?
Common causes: the column is wrapped in a function, the search has a leading wildcard, the parameter's type does not match the column, or the planner's statistics are stale. Index the expression, or change the query.
Is there a cost to extra indexes?
Yes. Each must be updated on every insert, update and delete, and occupies space and memory. Most databases record index usage — drop the ones with no reads, and the ones that are a prefix of another.