Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Some teams want to replace the cost-based optimizer's decisions with hints everywhere because plans were unpredictable during incidents. As the senior database authority, what position do you take?

I would not approve hints everywhere. Hints freeze a decision that was right for today's data, while the optimizer adapts as data grows, and most unpredictable plans trace back to fixable causes: missing or stale statistics, correlated columns, poor schema or non-sargable SQL. My position is to fix those causes first, allow hints or plan pinning only as a documented exception for critical queries with an owner and a review date, and invest in plan observability and regression detection so that plan changes are caught before customers notice.

Why this question is asked

When an incident is caused by a plan that flipped overnight, it is natural for a team to want control back, and hints look like control. A senior database authority has to take that frustration seriously while preventing a policy that creates bigger problems a year later. Interviewers ask this to see whether we can hold a principled technical position, explain it in terms teams accept, and still give them something practical. In this answer, we will recap what hints are, look at why they age badly, trace where unpredictable plans really come from, define a narrow exception process, add the observability that addresses the real fear, and consider the vendor angle.

1A Quick Recap of Hints and Plan Pinning

A hint is an instruction inside or attached to a SQL statement that tells the optimizer how to run it, for example use this index, join these tables in this order, or use a hash join. Plan pinning is a related idea: the database stores a known good plan for a statement and keeps using it. Oracle has SQL plan baselines, MySQL has optimizer hints written as comments such as /*+ JOIN_ORDER(r, c, o) */ and index hints, and SQL Server has query hints and Query Store forcing.

PostgreSQL is the exception: its community has deliberately chosen not to add native hints, preferring to fix the planner and statistics. The pg_hint_plan extension adds hint comments to PostgreSQL, but it is a separate project that must be installed, kept compatible with each major version and supported by whoever runs the database.

2Why Hints Age Badly

A hint encodes a decision based on the data at the moment someone wrote it. Suppose a team forces an index on orders(status) for a report because FAILED orders were 0.1% of the table. A year later a retry bug makes FAILED 30% of rows. The optimizer, left alone, would switch to a sequential scan; the hint keeps forcing 60 million random index lookups. The same happens with join order hints when one table grows a hundred times, or with a forced nested loop when a tenant ten times larger signs up.

So a hint trades occasional unpredictability for guaranteed staleness. Across hundreds of queries and many teams, nobody remembers why each hint exists, and they become a hidden layer of decisions that silently gets worse. The optimizer's ability to adapt is exactly what we pay for when we use a cost-based database.

3Where Unpredictable Plans Really Come From

In my experience, when we take the last ten plan incidents and look at each one, the large majority come from a handful of causes. The optimizer was given wrong information: statistics were stale after a bulk load, two correlated columns were assumed independent, a skewed column lacked detail in its statistics. Or the SQL was written so that no good plan exists: a function on an indexed column, a type mismatch, a catch-all OR for optional filters. Or the schema is missing the index the query needs. Prepared statements switching to a generic plan explain another share.

Each of these has a durable fix: ANALYZE in load jobs, extended statistics, a higher statistics target, rewritten predicates, a proper index. Fixing the cause makes the optimizer right for this query and for the next ten queries that touch the same table, while a hint fixes one query and only for now.

Step throughHandling a plan incident
  1. A plan flipped and got slow
  2. Estimate far from actual?
    YesFix statistics: ANALYZE, targets, extended statsNoLook at SQL and schema
  3. Predicate sargable and indexed?
    YesCheck settings and generic plansNoRewrite SQL or add the index
  4. Still unstable on a critical query?
    YesDocumented hint with owner and review dateNoDone, add a regression check

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

4A Narrow, Documented Exception

A flat ban would be wrong too. Sometimes the cause cannot be fixed quickly, a quarterly close report must run tonight, or the optimizer has a genuine blind spot. For those cases we allow a hint or a pinned plan as an exception, under three conditions. It applies to a named critical query, not a whole service. It has an owner who understands why it exists. And it has a review date, for example at the next major version upgrade or in six months, when someone checks whether it is still needed, using the root cause analysis that is attached to it.

We keep these exceptions in one register, with the tool used in each database: pg_hint_plan on PostgreSQL, optimizer hints on MySQL, SQL plan baselines on Oracle. That turns hints from folklore into a managed inventory, and the number of entries is itself a useful health measure.

5Addressing the Real Fear: Observability

The teams are not really asking for hints; they are asking not to be surprised during incidents. So the bigger investment goes into seeing plan changes early. We collect pg_stat_statements or performance_schema digests centrally, snapshot them frequently, and alert when a top query's mean time or blocks per call jumps after a deployment or a statistics refresh. auto_explain logs the plans of slow executions, so the plan is already captured when someone opens the incident. Critical queries get a regression check against a production-like copy before major upgrades.

With that in place, a plan flip becomes a ticket raised before customers notice instead of a page at 3 a.m., and the pressure for hints largely goes away.

6Weighing the Vendor Ecosystem

Finally, the cost side of a hint-heavy policy depends on the database. On PostgreSQL, hints mean depending on an extension for production correctness: every major upgrade must wait until the extension supports the new version, managed cloud services may or may not offer it, and behaviour can change between its releases. On Oracle, plan baselines are a supported core feature, so pinning is a smaller risk. A policy that says hints everywhere on PostgreSQL works against the design of the database we chose, and I would say so plainly when presenting the position.

7Follow-up questions

How would you measure whether the policy works?

I would track the number of plan-related incidents and their time to resolution per quarter, the share of top queries whose estimates are within ten times of actuals, how many plan regressions were caught by alerts before any customer impact, and the size of the hint register with how many entries are past their review date. If incidents fall and the register stays small and current, the policy works. If teams keep asking for exceptions, that points to a systematic cause we have not fixed yet.

What do you say to a team that was burned by a bad plan last week?

I would start by fixing their problem with them, including a temporary hint if that is what keeps tonight's run safe, and then do the root cause together. Showing that the flip came from, say, stale statistics after a load and fixing that in the job usually convinces a team more than any policy document.

Is plan pinning safer than hints?

It is often better managed, because the database stores the plan and can report when it would have chosen differently, as Oracle's baselines do. But it has the same core weakness: a plan that was good for old data stays in place when the data changes, so it needs the same owner and review discipline.

8Conclusion

In this answer, we took the position that hints should not replace the optimizer. Hints fix today's data and silently become wrong as data grows, while most bad plans come from causes we can fix durably: stale or missing statistics, correlated columns, poor schema and non-sargable SQL. We allowed hints and plan pinning only as a registered exception with an owner and a review date, invested in observability and regression alerts to remove the surprise that drives the request, and weighed the extension and upgrade risk of hints on PostgreSQL.

What to say in the interviewAbout 90 seconds aloud

Open with

My position would be no to hints everywhere, but yes to solving the problem behind the request. The teams want predictability, and hints look like it, but a hint encodes what was right for the data on the day it was written.

Then, if they want more

When a table grows a hundred times or a value's frequency changes, the optimizer would adapt and the hint keeps forcing the old plan. Across hundreds of queries that becomes a hidden layer of stale decisions.

When I go through past plan incidents, most come from fixable causes: stale statistics after loads, correlated columns treated as independent, skewed columns, non-sargable SQL, missing indexes, or generic plans for prepared statements. Fixing those helps every query on the table, not just one.

I would still allow a hint or a pinned plan as an exception for a critical query, with an owner, a link to the root cause and a review date, kept in a register: pg_hint_plan on PostgreSQL, optimizer hints on MySQL, SQL plan baselines on Oracle.

The main investment would be observability: central pg_stat_statements snapshots, alerts when a top query regresses after a deploy or a statistics change, and auto_explain so the plan is already captured when an incident starts. I would also point out that PostgreSQL deliberately has no native hints, so a hint-heavy policy there adds extension and upgrade risk. I would measure success by fewer plan incidents and a small, current register.

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 "Some teams want to replace the cost-based optimizer's decisions with hints everywhere...": https://scrivio-interview-library.netlify.app/databases/query-optimization/38f2094b91/