KOEN
All notes
DATA & PERFORMANCE

Should a fast PostgreSQL plan stay fixed when the data changes?

Imagine the same ten-thousand-row table with ten documents to review, then eight thousand. PostgreSQL 19’s pg_plan_advice documentation made me think about the context to keep beside a successful query plan.

A hand lifting a brass clip from a route card beside trays holding a few cards and a thick stack

The method that found ten sheets

Imagine a screen that shows documents awaiting review. Out of ten thousand documents, ten need attention. Later, the same screen has eight thousand documents to review.

The table still has the same number of rows, and the filter is unchanged. In this fictional table we select rows where needs_review is true. The matching proportion works out to 0.1% in the first case and 80% in the second. These are invented counts, not database measurements.

Would holding on to the method that was fast before keep it fast now? Saying it is the same query does not quite settle the question. There are rather more sheets to find.

One feature that caught my attention in the November 19, 2026 PostgreSQL 19 announcement was pg_plan_advice. The official documentation describes a language for expressing, reproducing and changing key planning choices. It offers a way to retain choices believed to work well or experiment with alternatives.

The documentation opens with a warning too. A planner can adjust its choices when the data distribution changes. Advice that prevents that adjustment can lead to a poor plan.

That brought me back to the document tray. Describing both situations as a ten-thousand-row table would leave out a fairly important difference between ten matches and eight thousand.

The proportions alone cannot tell us whether an index or a full scan would be faster. Indexes, row sizes, what must be read and the environment also matter. I have not run PostgreSQL or timed competing plans here. The small calculation establishes only that an unchanged filter can match a very different share of the data.

Keeping the conditions beside the choice

The wish to preserve a working method is understandable. If a particular choice resolved a problem, we may want to use it again. But the chosen method is probably not the only thing worth preserving.

If I inherited this imaginary screen, I would want to know the query and its inputs. What was in the table then, and how many documents matched? A plan needs its measurement conditions and observed results beside it before a claim such as “it was fast” becomes something we can compare again.

Nor does pg_plan_advice replace the planner wholesale. The documentation explains that it constrains the planner’s choices. One example takes just the join-order portion of generated advice and applies that. Retaining one choice is different from forcing every decision to remain identical.

I like being able to distinguish those scopes. Narrowing the problematic choice gives less reason to freeze unrelated choices along with it. A narrow constraint still needs checking against the current data and query, though; its scope alone does not make it safe in every situation.

After supplying advice, we also need to read what actually applied. The documentation describes EXPLAIN feedback for whether advice matched its target or could not apply, among other outcomes. Confirming that advice applied and measuring whether it improved performance remain separate tasks.

For our document tray, I would not leave the old matching-row count blank. Someone could later look only at the query text and reuse the earlier fix. When the data has changed, the old choice can be a comparison candidate without bringing its conclusion along for free.

This is not an account of operating a new extension or upgrading a server. It is a reflection on the official documentation and the records needed to reconsider an earlier choice. A real environment would still need its own comparison.

I would leave a small note beside the old plan: ten documents needed review then. Faced with today’s eight thousand sheets, we could finally ask again whether the clip belongs in the same place.

Sources

All notes