PostgreSQL 19 can say a query hint matched even when it slows the query
In a synthetic test on ClickHouse Managed Postgres, a bitmap-scan hint helped when failed events were clustered. After the data changed, PostgreSQL still applied the hint, but the unhinted query ran faster.
In a ClickHouse test, a PostgreSQL 19 scan hint cut execution time from roughly 1.46 seconds to under 10 milliseconds. When failures became common near the start of the same table, PostgreSQL still followed the hint, but the default plan ran faster. For teams tuning recurring SQL generated by an analytics agent, the test shows why checking the plan and measuring its performance are separate jobs.
What matched actually means
PostgreSQL’s Advice Feedback documentation says matched means the planner saw all the named targets together at a point when the advice could be enforced. It does not, by itself, show that the planner complied. The docs show an index hint for a nonexistent index marked matched, inapplicable, failed. Read the other flags and check the actual plan node before concluding the hint took effect.
Same query, different data
In a November 25 ClickHouse engineering post, Colton Shepard tested a query returning the first 10 failed events in ID order. The initial synthetic table put 50,000 failures after 10 million successful events. The default primary-key scan discarded those 10 million rows before returning the answer. ClickHouse reported execution times of 1,461.947 milliseconds without advice and 9.687 milliseconds with advice to use a bitmap heap scan.
Shepard then set every third row to failed and ran VACUUM ANALYZE. The unhinted primary-key scan now discarded only 20 rows before returning ten matches. It took 0.052 milliseconds, compared with 368.866 milliseconds for the hinted query. The latter plan showed a Parallel Bitmap Heap Scan on events and listed BITMAP_HEAP_SCAN(events) / matched / without a failed flag. The scan node and the feedback together show that the planner followed the hint even though it no longer helped. These timings are from a synthetic example on ClickHouse Managed Postgres, not a production benchmark or a prediction for other deployments.
What to test before keeping a hint
For a recurring agent-generated query, compare hinted and unhinted execution on representative data. Include cases where qualifying rows are rare and where they are easy to find in the requested order. Check the returned rows for correctness, then separately record the actual plan, execution time and work done. In ClickHouse’s example, LIMIT 10 stayed the same even as the work needed to find those rows changed.
Recheck retained hints after a material change in the data. As the PostgreSQL documentation warns, plan advice constrains the planner’s choices and can keep it from adapting. Use matched to diagnose how the advice was handled; use the measurements to decide whether to keep it.
sources
- ClickHouse Engineering: Hints and hazards: pg_plan_advice in PG19clickhouse.com
- PostgreSQL 19 documentation: pg_plan_advicewww.postgresql.org
comments · 0
- EKOS’s pending BIRD submission pairs a SQLite-tuned run with a separate hidden-test scoreDec 3, 2026
- MotherDuck rolls out DuckDB 2.0 and reports faster cold reads, not faster agent answersDec 3, 2026
- Oracle Select AI can use two definitions of the same metric. Source order won’t break the tieDec 3, 2026