All jobs / Database administrator / Performance
Database administrator interview question · 3–5 years
The plan cache is full of thousands of near-identical statements that differ only by literal values. Impact and fix?
The strongest answer
Every statement compiles from scratch and evicts useful plans, wasting CPU and memory; the fix is parameterised queries in the application, with the engine’s forced parameterisation as a stopgap
Why it works
Exactly — unparameterised SQL is the root cause, and it usually also means injection risk.
What a good answer covers
- Literals defeat plan reuse.
- Parameterise in the application.
- Forced parameterisation as a stopgap.
- Also an injection smell.
Answers that fall short
- Close, but not the strongest: Increase the memory available for the plan cache so more plans fit
More memory means a bigger pile of one-use plans. - Weak: It is expected behaviour for a busy system and costs nothing
Compilation is real CPU, and the useful plans are being evicted. - Red flag: Turn the plan cache off so it stops filling up
Without a cache every query compiles every time.
Who gets asked this
More Performance questions
- 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?
- In plain words, how does an index make a query faster?
- A developer suggests indexing every column “just in case”. Your response?
- An application opens a new database connection for every web request. Concern?
- A query is slow. What is the first thing you look at?