Take me from that sample to a query plan, what does ANALYZE compute, and how does the planner use it?
This is the follow-on question, and it is where a memorised answer runs out. Listing the statistics ANALYZE computes is a warm-up; the interviewer is waiting for the arithmetic that turns a WHERE clause into a row count, because that number is what chooses the scan type, the join order, and whether parallelism is worth attempting. The strongest version of this answer ends somewhere useful: not with a description of the catalog, but with what you would actually do when a plan degrades and nobody changed any SQL. This page covers how to narrate the chain in about ninety seconds, which two statistics carry most of the weight, and how to name the failure mode that a bigger sample cannot fix.
What the interviewer is scoring
Score points for naming the statistics that actually drive the estimate, n_distinct and the most-common-values list, and for connecting them to a selectivity multiplied by the estimated row count.
In short: They want the chain from raw sample rows to per-column statistics, and then how the planner turns a WHERE clause into a row estimate.
The spoken answer, backed by captured output
- The full 90-second answer, written first person, the way you would actually say it
- How I reason through it: the mechanism, the decision points, and where the claim stops
- Verification steps with output captured verbatim from a controlled PostgreSQL 18 lab run.
- Worked responses to the 3 follow-up probes listed above, plus the traps that lose the point
Card required. Cancel before day 7 and you are not charged.
How to reason through it
- List what ANALYZE computes per column: null fraction, average width, n_distinct, most-common values and their frequencies, a histogram, and physical correlation.
- Say where it lands: the per-column statistics catalog, surfaced readably through the pg_stats view.
- Explain the planner's move: predicate → selectivity → selectivity × estimated rows = estimated output rows.
- Note that a wrong n_distinct or a missing most-common value is what makes estimates, and plans, go bad.
- Close on the diagnostic: find the lowest node where estimated and actual rows diverge.
What I would verify
- Read the plan from the bottom and find the first node where estimated and actual rows separate materially.
- Check whether the filtered value appears in the column's most-common-values list.
- Compare the distinct estimate against reality when the predicate is an equality on a low-cardinality column.
- Test whether the error only appears when two predicates combine; that points at correlation, not sample size.
Follow-ups they push on
- The estimate is out by two orders of magnitude on a single equality predicate. Where do you look?
- Two predicates, each estimated correctly, but combined the estimate collapses. Why?
- Can you override any of these numbers?
The probes are open. Pro carries the spoken answer, the reasoning behind it, and the verification steps, including a worked response to each of these.
Concepts tested
Learn it, run it, then say it
Three steps, in order. Nothing here is a detour.
1 · Learn the mechanism
Understand it before you try to say it.
2 · Practise it for real
Run it once so the answer describes something you have seen.
3 · Rehearse the next question
Keep going while the mechanism is fresh.
Questions that go with this one
- staff · ProYou've got a 50 TB table. Walk me through what ANALYZE actually does at that size, does it read every page?The step before this one: where the sample those statistics come from is drawn.
- mid · FreeYou want to measure a table's access pattern cleanly after a change. How do you reset just that table's statistics without wiping the cluster?What ANALYZE maintains, which is the half a counter reset never affects.
- senior · ProA query became slow after a deploy. Show a safe production triage that separates estimate error, execution or I/O cost, lock waits, and a cleanup horizon. Then explain what VACUUM can reclaim, how freezing protects availability, and how you would prove physical bloat.The estimate half of this triage, taken all the way down to the statistics.