All jobs / Database administrator / Performance
Database administrator interview question · 0–1 years
You index a status column that has three possible values and the query is no faster. Why?
The strongest answer
It is not selective — most rows match, so following the index would still touch nearly every row and a scan is cheaper; indexes pay when the lookup eliminates most of the table
Why it works
Right — selectivity, not the existence of an index, decides whether a seek beats a scan.
What a good answer covers
- Selectivity decides seek or scan.
- Matching most rows is not selective.
- Low cardinality helps rare values.
- Do not hint around the planner.
Answers that fall short
- Close, but not the strongest: The statistics must be out of date, so the planner does not realise the index is there
Stale statistics do cause ignored indexes, but here the planner is probably correct: the filter matches too much. - Weak: Three values is too few for an index to work at all — indexes only help on unique columns
Low-cardinality indexes can help — for the rare value, or as part of a composite — they just do not help for the common one. - Red flag: I would force the planner onto the index with a hint, so we get the benefit of the index we built
Hints replace the planner’s costing with your guess and long outlive the reason you added them.
Who gets asked this
More Performance questions
- Dozens of sessions are waiting and the app has slowed to a crawl. How do you find the culprit?
- The application logs show deadlocks a few times a day. What do you do?
- Several sessions sit “idle in transaction” for hours. Why does that matter and what do you do?
- A query that ran in milliseconds now takes minutes, right after a large data load. First suspect?
- The database shows thousands of identical tiny queries per page load. What is happening and what do you…
- What is a covering index and when is it worth it?
- Hundreds of application pods each keep a pool of twenty connections. The database is out of connections. Fix?
- The same parameterised query is fast for most customers and terribly slow for one large customer. What is…