All jobs / Database administrator / Performance
Database administrator interview question · 0–1 years
Does the column order in a composite index matter?
The strongest answer
Yes — the index is sorted by the leading column first, so queries must filter on that leading column to use it; equality columns go first, ranges last
Why it works
Exactly — leading-column rule, and equality before range.
What a good answer covers
- Leading column drives usability.
- Equality first, range last.
- Order follows the queries.
- Not alphabetical.
Answers that fall short
- Close, but not the strongest: A little; the database can usually use any subset of the columns
Skipping the leading column usually means the index is not used for seeks. - Weak: No, the optimiser reorders the columns as needed
The optimiser cannot change the physical sort order of an index. - Red flag: No, so I put the columns alphabetically to keep things tidy
Alphabetical order ignores how queries actually filter.
Who gets asked this
More Performance questions
- You index a status column that has three possible values and the query is no faster. Why?
- 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?