All jobs / Database administrator / Performance
Database administrator interview question · 1–3 years
The order-history page issues one query per line item, and some customers have thousands.
The database shows thousands of identical tiny queries per page load. What is happening and what do you suggest?
The strongest answer
An ORM loads a parent then one query per child — N+1; the fix is eager loading or a join so a page is a few queries, and I show developers the log as proof
Why it works
Exactly — round trips are the cost; collapse them, and bring evidence to the developers.
What a good answer covers
- Recognise N+1 from the pattern.
- Eager load or join.
- Round trips are the cost.
- Show developers the log.
Answers that fall short
- Close, but not the strongest: The queries are fast individually, so it is fine as long as the page loads
Fast individually still means thousands of round trips and connection time per page. - Weak: Add an index so each of the tiny queries is faster
The queries are probably already indexed; the problem is their number. - Red flag: Cache every query result in the application so the database stops seeing them
Caching hides a shape problem and adds staleness.
Who gets asked this
More Performance questions
- 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…
- The plan cache is full of thousands of near-identical statements that differ only by literal values. Impact…
- A nightly job updating a few million rows locks the entire table and blocks the application. Why, and what do…
- One row holding a global counter is updated by every request and has become the bottleneck. Options?
- A table is partitioned by month but queries still scan every partition. Why?
- The server is busy and nobody can say why. How do you use wait statistics to answer that?