Lobste.rs Databases· clickhouse.com via eatonphil·· 7d ago
ClickHouse Tests PostgreSQL 19 pg_plan_advice and Its Hazards
Hints and hazards: pg_plan_advice in PG19
Key Takeaway
ClickHouse tests PostgreSQL 19’s pg_plan_advice and pg_stash_advice on ClickHouse Managed Postgres, using scan and JOIN-order hints to address planner misestimates.
Why It Matters
Using ClickHouse Managed Postgres tests, the article shows where PostgreSQL 19 plan advice helps and how stale or poor advice can degrade query performance.
Technical Breakdown · Distilled from the original source
How advice works
- In PostgreSQL 19,
pg_plan_advicesets session-level advice for scan methods, join order and methods, parallelism, and other planner choices.pg_stash_adviceoffers the same controls keyed by query ID, so advice need not be set before each execution. - Advice discourages alternatives rather than forcing a particular plan. If it cannot be followed, it may be ignored in part or in full.
EXPLAIN (ANALYZE, BUFFERS, PLAN_ADVICE)shows the chosen plan and whether supplied advice matched.matchedindicates adoption, not a performance gain.
Measured gains and regressions
- With failed rows clustered at the end of the table, the primary-key scan discarded 10 million rows before finding the requested 10.
BITMAP_HEAP_SCAN(events)cut execution time from roughly 1,462 ms to 9.7 ms. In a separate test, changing the join order made better use of the selective filter onaccounts, yielding a nearly 200-fold speedup. - After every third row was marked failed, the default primary-key scan took 0.052 ms. The same bitmap advice took about 369 ms, roughly 7,000 times longer, and still reported
matched.
Production use
- Try conventional tuning first. When advice helps, use
SET LOCALinside a transaction to avoid affecting other queries, and retest periodically. Advice stored bypg_stash_adviceis not WAL-logged, so HA failover needs special handling.
Source: Lobste.rs Databases· clickhouse.com
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.