Quick revision
The short answer
I would make query plans a small, routine part of delivery instead of an incident tool: a short plan template in pull requests for new or changed queries on large tables, a shared environment with production-like anonymised data where plans mean something, automated EXPLAIN checks in CI that flag only clear problems, and central collection of real slow plans with auto_explain and pg_stat_statements. Training built on our own incidents and a few database champions per area keep it going without a central team becoming a bottleneck.
What to remember
In this answer, we treated plan reading as a habit to build with mechanisms. We first saw why teams skip plans: meaningless laptop data, missing skill and no step in the workflow. We then added a narrow plan template in pull requests, a shared anonymised environment with production-like volume, a few high-signal CI checks with waivers, central collection of real slow plans with auto_explain and pg_stat_statements, and training from our own incidents with champions in each area, all sized so that delivery stays fast.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would make query plans a small, routine part of delivery instead of an incident tool: a short plan template in pull requests for new or changed queries on large tables, a shared environment with production-like anonymised data where plans mean something, automated EXPLAIN checks in CI that flag only clear problems, and central collection of real slow plans with auto_explain and pg_stat_statements. Training built on our own incidents and a few database champions per area keep it going without a central team becoming a bottleneck.
Why this question is asked
Most query performance problems are visible in a plan long before they hurt anyone, yet many teams only open EXPLAIN output during an incident at 2 a.m. Interviewers ask senior candidates this question to see whether they can change a habit across many teams with mechanisms rather than slogans, and whether they understand what makes a plan meaningful in the first place. In this answer, we will look at why plans are skipped today, then build the practice in layers: what we ask for in reviews, where plans can be produced realistically, what we automate, how we bring real production evidence back to teams, and how we train people, with attention to keeping delivery fast.
1Why Teams Skip Query Plans
Before adding process, it helps to understand why 25 services' worth of engineers do not look at plans today. Usually there are three reasons. Plans on a laptop database with 500 rows are meaningless, because every query is fast and the planner picks sequential scans for tiny tables, so engineers learn that EXPLAIN tells them nothing. Reading plans is a skill few people were taught, so the output looks like noise. And nothing in the workflow asks for it, so it only happens when something breaks.
Each reason suggests a fix: realistic data, a little teaching, and a light step in the workflow. The goal is not that everyone becomes a database expert. It is that the queries that matter, new or changed queries on large tables, get a quick look before they ship, and that real slow queries are visible to the team that owns them.
2A Light Plan Requirement in Pull Requests
The first mechanism is a pull request rule with a narrow scope: any new or changed query that touches a table above a size threshold, say 1 million rows, includes its plan from the shared environment. Narrow scope matters. If every query needs a plan, people paste plans nobody reads; if only the risky ones do, reviewers actually look.
A short template makes the plan readable in under a minute. It asks for the EXPLAIN (ANALYZE, BUFFERS) output and three answers: are estimated and actual rows within about ten times of each other at each node, which scan types are used on large tables (a sequential scan on a 50 million row table needs a reason), and how many pages the query touches. Those three questions catch most problems, and they teach people what to look for each time they fill the template in.
3A Place Where Plans Mean Something
A plan is only meaningful on data that resembles production in volume and distribution, because the planner's choices depend on statistics. So the platform team provides a shared environment, refreshed regularly, with production volume and anonymised values: names, emails and other personal data are replaced, but row counts, value frequencies and relationships are kept. A table with 200 million orders and a few huge tenants must look like that in this environment too, or the plans will lie.
This is the most expensive part of the plan, in storage and in the work to anonymise correctly, and it is also what makes everything else work. If the full copy is too costly, a scaled copy of the largest tables with the same skew is a reasonable first step.
4Automation in CI Without Noise
Automation catches what people forget. In CI, we start a database seeded with realistic statistics or data, collect the repository's queries (for Spring services, the SQL Hibernate generates while integration tests run, captured through a statement logging hook), and run EXPLAIN on each. Plain EXPLAIN is enough here; it does not execute anything.
- Developer changes a query
- Touches a table above 1M rows?YesPlan template in the pull requestNoNormal review only
- CI runs EXPLAIN on seeded dataflags only clear problems
- Finding is real?YesFix before mergeNoWaive with a reason
- Production slow plans collectedauto_explain and pg_stat_statements feed back to the team
5 steps in order. Play them, or step through them one at a time.
The rules should be few and high-signal: a sequential scan on a table above the size threshold, a total cost above an agreed limit, or a new query whose plan cost jumped compared with the main branch. Each finding links to an explanation and can be waived with a one-line reason in the pull request. That waiver is important: a check that cannot be overridden gets disabled, and a check that flags everything gets ignored.
5Real Evidence From Production
Pre-merge checks catch some problems, but data changes after release. So the platform also collects what happens in production: pg_stat_statements on every database for the top queries by total time, and auto_explain logging the plans of statements slower than a threshold, with timing off and sampling to keep overhead low. These go to a central place where each team sees its own top queries and slow plans each week.
This changes the conversation. Instead of hypothetical advice, a team sees that their invoice search ran 1.2 million times last week, took 14 hours of database time, and here is its plan. Real problems motivate people far more than rules do.
6Training and Champions
Finally, people need a little skill. A 90-minute session built from our own past incidents, showing the actual plan, the wrong estimate and the fix, teaches more than any generic course, because engineers recognise their own tables. We then ask for one or two database champions in each area of roughly five services: people who are interested, get a bit more training, review the plan templates in their area and bring hard cases to the platform team.
To protect delivery speed, the whole practice should cost minutes, not days: the template is short, only risky queries need it, CI runs automatically, and champions are inside the teams, so nobody waits for a central database review board. We would measure success by fewer query-related incidents and by how many slow queries are found from dashboards before customers notice.
7Follow-up questions
How do you avoid CI plan checks becoming noisy and ignored?
I keep the rules few and specific, such as sequential scans on tables above a size threshold or a big cost increase compared with the main branch, and I tune thresholds on real findings during a trial period before making the check blocking. Every finding must explain itself and link to a fix, and engineers can waive one with a short reason that reviewers see. I also track the waiver rate: if most findings are waived, the rule is wrong and I change it rather than pushing people.
Why not have a central DBA review every query?
With 25 services and frequent releases, a central review becomes a queue and slows delivery, and the reviewers lack context about each service. Spreading the basic skill to champions inside teams, backed by automation and a small expert group for hard cases, scales better and keeps ownership with the people who change the code.
What makes a production-like environment trustworthy for plans?
Similar row counts, similar value distributions, including skew such as a few very large tenants, similar indexes and similar planner settings. Values can be anonymised freely as long as frequencies and relationships stay realistic, because the planner cares about statistics, not about real names.
8Conclusion
In this answer, we treated plan reading as a habit to build with mechanisms. We first saw why teams skip plans: meaningless laptop data, missing skill and no step in the workflow. We then added a narrow plan template in pull requests, a shared anonymised environment with production-like volume, a few high-signal CI checks with waivers, central collection of real slow plans with auto_explain and pg_stat_statements, and training from our own incidents with champions in each area, all sized so that delivery stays fast.
Open with
I would start by asking why people skip plans. Usually plans on small local data are meaningless, few engineers were taught to read them, and nothing in the workflow asks for them.
Then, if they want more
So I would address each one. First, a pull request rule with narrow scope: new or changed queries on tables above about a million rows include an EXPLAIN ANALYZE with buffers and a three-question template, estimated versus actual rows, scan types on large tables, and pages touched. That takes minutes and teaches what to look for.
Second, a shared environment with production-like volume and anonymised data, because plans only mean something when the statistics resemble production.
Third, CI automation that runs EXPLAIN on the queries our services generate against seeded data and flags only clear problems, like a sequential scan on a big table or a cost jump against main, with a simple waiver so it does not become noise.
Fourth, real evidence: pg_stat_statements and auto_explain on every database, with each team seeing its own top queries and slow plans weekly. Real numbers from their own service motivate people more than rules. Finally, a short training built from our own incidents, plus one or two database champions per area who review templates locally, so there is no central bottleneck.
I would judge it by fewer query incidents and more problems found before customers notice.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your teams rarely look at query plans until production incidents. How would you make...": https://scrivio-interview-library.netlify.app/databases/query-optimization/005183381c/