Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Plan regressions caused three severe incidents last year in different products. How would you set up an organisational capability to prevent and respond to them?

I would make query performance part of every release: baseline the top queries, detect new or changed plans after deploys, statistics jobs and upgrades, and alert on them. A small database reliability function would own that tooling, the runbooks and training, while product teams keep owning their queries. On top, a shared playbook (identify, compare plans, mitigate quickly, then find the root cause), governed plan stability tools per database, and metrics on incidents and time to mitigate show whether the investment pays.

Why this question is asked

Three severe incidents in different products from the same cause is a pattern, not bad luck. It says the organisation has no shared way to notice that a plan changed, and no common response when it does. Interviewers ask this to see whether a senior engineer can turn repeated firefighting into a capability: tooling, ownership, process and measurement that outlast any single incident. In this answer, we will look at what the incidents tell us, treat query performance as part of the release, decide who owns what, define the response playbook, govern plan stability tools, and measure the result.

1What Three Incidents Are Telling Us

A plan regression happens when the database, given the same SQL, starts executing it in a different and slower way. The usual triggers are new statistics, data growth, a schema change, a parameter change or a version upgrade. None of these is a code deploy, so ordinary release checks never see them.

When we review the three incidents together, we usually find the same gaps: nobody knew what the plan was before, the change was detected by customers rather than by monitoring, each team improvised its diagnosis, and the fix was a forced plan that nobody removed later. Each gap maps to a part of the capability we build.

2Make Query Performance Part of the Release

The first part is detection. For each production database we keep a baseline of the top queries by total time from pg_stat_statements, with their plan shape. After every deploy, every scheduled statistics job and every upgrade, an automated comparison flags queries whose mean time or plan changed beyond a threshold. auto_explain logs plans of slow statements so that the evidence exists when we need it.

SQL
-- Nightly snapshot into a history table, compared after each change
INSERT INTO perf.query_baseline (captured_at, queryid, calls, mean_ms)
SELECT now(), queryid, calls, mean_exec_time FROM pg_stat_statements;
-- Alert: queries now more than 3x slower than their 7-day median
-- (computed by the monitoring job from perf.query_baseline)

Notice that this does not require product teams to do anything new day to day. The comparison runs in the platform, and a team only hears about it when one of its queries changed. Performance tests on critical flows in the pipeline add a second net for regressions that come with code changes.

3Who Owns What

Ownership decides whether a capability survives. If a central team owns every query, it becomes a bottleneck and product teams stop learning. If nobody owns the tooling, it decays. So I would fund a small database reliability function, two or three engineers for a company of this size, that owns the detection tooling, the runbooks, the plan stability tools and training. Product teams keep ownership of their queries, their indexes and the fixes, with the reliability engineers as advisers during incidents and in design reviews.

Step throughOwnership of the capability
  1. Product teamsown their queries, indexes, fixes and on-call
  2. Response playbookshared steps every team follows
  3. Database reliability functiontooling, runbooks, training, advice
  4. Detection platformbaselines, plan diffs, auto_explain, alerts
  5. DatabasesPostgreSQL, SQL Server, Oracle, each with its tools

5 layers, from the top down. Step through them one at a time.

Central tooling and expertise underneath, product ownership on top.

The split also gives a clear answer when something breaks at 3 a.m.: the product on-call engineer runs the playbook and pages a database reliability engineer if the first steps do not resolve it.

4A Response Playbook Everyone Uses

When a regression happens, speed matters more than elegance, so the playbook separates mitigation from root cause.

Step throughPlan regression response
  1. Identify the queryalert, pg_stat_statements, traces
  2. Compare plansbaseline plan versus current EXPLAIN ANALYZE
  3. Mitigate quicklyANALYZE, hint, index, feature flag
  4. Customers safe?
    YesFind root causeNoEscalate to database reliability
  5. Fix root causestatistics, index, rewrite
  6. Remove mitigation and write reviewupdate baseline and runbook

6 steps in order. Play them, or step through them one at a time.

Mitigate first, understand second, and never leave the mitigation behind.

The quick mitigations are deliberately cheap and reversible: an ANALYZE to refresh statistics, a hint or forced plan, a missing index built concurrently, or a feature flag that turns off the expensive path. Only once customers are safe does the team dig into why the plan changed and fix it properly, for example with extended statistics or a query rewrite, and then remove the temporary mitigation.

5Govern Plan Stability Tools

Each database offers a way to pin a plan. SQL Server has Query Store, which records plans over time and can force a known good one. Oracle has SQL plan baselines, which accept only verified plans. PostgreSQL has no built-in plan forcing, but the pg_hint_plan extension can attach hints to queries. These tools are powerful, and that is the risk: a forced plan that was right last year can be the cause of next year's incident when data changes.

So the capability includes rules for them. Each forced plan or hint has an owner, a reason linked to an incident, and a review date, and the platform lists them so the reliability function can review them quarterly. We decide per database which tool is allowed, rather than letting each team discover one under pressure.

6Measure Whether It Pays Off

Funding a new function needs evidence. We track the number of plan regression incidents per quarter and their severity, the time from regression to detection, the time to mitigate and the share detected by monitoring rather than by customers. A realistic goal is that most regressions are caught by alerts before users notice, and that the time to mitigate drops from hours to tens of minutes. If after a year the numbers have not moved, we revisit the design instead of assuming the investment works.

7Follow-up questions

Why not let each product team build its own tooling?

Because the three incidents already show that teams under delivery pressure do not build it until after an incident, and when they do, each version is different. Detection and plan stability tools are the same problem everywhere, so building them once is cheaper and more reliable.

How do you get teams to adopt the playbook?

Use it in every incident review, keep it short, link it from alerts, and run a game day where a team fixes a deliberately broken plan in staging. People adopt a playbook they have practised and that saved them time once.

Is forcing plans a bad practice?

No, it is a valid mitigation and sometimes a long-term choice for a critical query whose good plan is well understood. It becomes bad practice when forced plans are invisible, ownerless and never reviewed, which is exactly what governance prevents.

8Conclusion

In this answer, we saw how to turn repeated plan regression incidents into a capability. We make query performance part of each release with baselines and plan change detection after deploys, statistics jobs and upgrades, fund a small database reliability function for tooling, runbooks and training while product teams own their queries, use a shared playbook that mitigates first and fixes the root cause next, govern plan stability tools per database, and measure incidents and time to mitigate to prove the value.

What to say in the interviewAbout 80 seconds aloud

Open with

Three incidents in different products tells me this is an organisational gap, so I would build a capability rather than fix three queries. First, detection: query performance becomes part of the release.

Then, if they want more

We baseline the top queries from pg_stat_statements per database, compare after every deploy, statistics job and upgrade, flag new or changed plans and big slowdowns, and keep auto_explain on so plans of slow statements are recorded.

Second, ownership: a small database reliability function, two or three people, owns that tooling, the runbooks and training, while product teams keep owning their queries and fixes, with the reliability engineers as advisers.

Third, a playbook every team follows: identify the query, compare its plan with the baseline, mitigate quickly with something reversible such as ANALYZE, a hint, an index or a feature flag, and only then find the root cause, fix it properly and remove the mitigation.

Fourth, governance of plan stability tools, Query Store in SQL Server, plan baselines in Oracle, pg_hint_plan in PostgreSQL: each forced plan has an owner, a reason and a review date. Finally I would measure incidents per quarter, time to detect and time to mitigate, so after a year we can show whether the investment paid off.

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.
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 "Plan regressions caused three severe incidents last year in different products. How...": https://scrivio-interview-library.netlify.app/databases/query-optimization/562a688275/