Query Plan Stability

Hint vs let optimiser decide.

Overview

Query plan stability ensures database query plans stay predictable across statistics updates and version upgrades. The optimizer’s job is to pick the best plan given current statistics; when statistics drift or the optimizer picks a different plan after an upgrade, queries that ran in milliseconds suddenly take seconds. The discipline is in plan-cache awareness, judicious use of query hints, freshness of statistics, and quarterly plan review against actual production traffic.

The approach

The practical approach is to keep statistics fresh (per-table analyze cadence matched to write volume), monitor plan-cache behavior, use query hints sparingly and only when the optimizer is provably wrong, run quarterly plan reviews against pg_stat_statements or equivalent, and document the per-database plan-management policy so the rules are reviewable. Stable plans are downstream of fresh statistics; hints are the last resort.

Why this compounds

Plan stability discipline compounds across queries and versions. Each stable plan preserves predictable performance; each fresh-statistics table prevents the optimizer from picking wrong plans; the team builds intuition for what makes plans stable rather than what makes them fast today. The opposite, where plans drift unmonitored, surfaces as surprise slow queries every quarter.

Plan stability discipline is a database discipline that pays off across years. Nova AI Ops integrates with database telemetry, surfaces plan patterns, and supports the team’s database engineering discipline.