Re: pg_plan_advice
Robert Haas <robertmhaas@gmail.com>
Attachments
- v13-0001-Store-information-about-range-table-flattening-i.patch (application/octet-stream) patch v13-0001
- v13-0002-Store-information-about-elided-nodes-in-the-fina.patch (application/octet-stream) patch v13-0002
- v13-0003-Store-information-about-Append-node-consolidatio.patch (application/octet-stream) patch v13-0003
- v13-0004-Add-pg_plan_advice-contrib-module.patch (application/octet-stream) patch v13-0004
On Mon, Jan 12, 2026 at 12:13 PM Robert Haas <robertmhaas@gmail.com> wrote: > If not, I'll rearrange > the series to move 0004 to the front, and plan to commit that first. That rearrangement got done in v11, and I've now committed that patch after fixing a few typos that I found. Cautiously, woohoo, but let's see if anything breaks. Here's v13. Aside from dropping the now-committed patch, the other big change here is that I've fixed the way bitmap heap scans work by reducing scope. Previously, you could write things like BITMAP_HEAP_SCAN(foo some_foo_idx) or BITMAP_HEAP_SCAN(foo &&(foo_a_idx foo_b_idx)) to try to compel a particular choice of index with a bitmap heap scan; however, it didn't actually work. I've now removed that, and now all of the arguments to BITMAP_HEAP_SCAN() are relation identifiers, and it specifies only that they should use some kind of bitmap heap scan. I'm not sure that this is the right thing to do, but it might be, for a couple of reasons: 1. The decision as to what should be included in a bitmap path is not made by the general costing machinery, but by choose_bitmap_and(), which uses its own special algorithm. A general principle of pg_plan_advice is that it doesn't let you force the optimizer to consider options that are rejected for reasons other than cost. This is a grey area. choose_bitmap_and() considers cost, but it also has other heuristics to limit the search space. We could allow overriding the former part of the heuristic but not the latter, but that seems complicated, and might also make this whole thing even more confusing to use, since it would be really unclear why you could force some index combinations and not others. We could also allow forcing any combination, but that needs a lot of thought, since it deviates from the general design principle and might open a king-sized can of worms. Point being, the idea that BITMAP_HEAP_SCAN() has no business allowing an index specification in the first place is not completely without merit. 2. The only situations in which we consider multiple actual bitmap paths (vs. potential bitmap paths, as discussed in the previous point) is when there are possibly-useful parameterizations that we don't want to ignore. However, I studied what happens in the core regression tests, and it seems like we don't really have that many test cases where just forcing some kind of bitmap heap scan wouldn't be good enough. To use a parameterized bitmap heap scan path, we have to be under the inner side of a nested loop with the parameterized rel on the other side, so if the advice produces any other join order or join method, then the parameterized paths won't even be considered and there's only one path to choose from. However, it is true that we might make the wrong decision about which bitmap path to use on the inner side of a parameterized nested loop. In the future, that could be addressed either by adding control over choice of parameterization or by re-adding something like what I had in earlier patch versions where you can specify particular indexes. But. I don't think we need to decide right now which of those things we might ultimately want to do. (Another interesting point is that in a healthy number of cases where we consider both parameterized and unparameterized bitmap paths, we consider the same indexes or sets of indexes in both cases.) I've gone ahead and removed the "WIP" designation from the pg_plan_advice patch in this version. There are still a few areas that need some more investigation, and I'm sure there are still bugs, but I feel like the bitmap scan thing was the last really big area where there was a huge problem staring any potential reviewer right in the face. The remaining XXX comments are things where review comments would actually be pretty helpful -- not to tell me that I have an XXX comment, but to suggest what the resolution might be. Of course, I'll continue looking into that on my own, as well. Thanks to all who have reviewed so far, and please keep it coming. I am especially in need of more code review at this point. -- Robert Haas EDB: http://www.enterprisedb.com
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
pg_plan_advice: Fix another unique-semijoin bug.
- 4321dcad475b 19 (unreleased) landed
-
pg_plan_advice: Export feedback-related definitions.
- c644aca24089 19 (unreleased) landed
-
pg_plan_advice: Fix a bug when a subquery is pruned away entirely.
- 0f93ebb3112d 19 (unreleased) landed
-
pg_plan_advice: Add alternatives test to Makefile.
- 1faf9dfa4796 19 (unreleased) landed
-
pg_plan_advice: Handle non-repeatable TABLESAMPLE scans.
- 3311ccc3d24b 19 (unreleased) landed
-
pg_stash_advice: Allow stashed advice to be persisted to disk.
- c10edb102ada 19 (unreleased) landed
-
Add pg_stash_advice contrib module.
- e8ec19aa321a 19 (unreleased) landed
-
pg_plan_advice: Avoid assertion failure with partitionwise aggregate.
- e2ee95233cab 19 (unreleased) landed
-
pg_plan_advice: Invent DO_NOT_SCAN(relation_identifier).
- 6455e55b0da4 19 (unreleased) landed
-
Add an alternative_plan_name field to PlannerInfo.
- 26255a320733 19 (unreleased) landed
-
pg_plan_advice: Refactor to invent pgpa_planner_info
- 5dcb15e89af2 19 (unreleased) landed
-
Respect disabled_nodes in fix_alternative_subplan.
- 47c110f77e75 19 (unreleased) landed
-
get_memoize_path: Don't exit quickly when PGS_NESTLOOP_PLAIN is unset.
- dc47beacaa0b 19 (unreleased) landed
-
test_plan_advice: Set TAP test priority 50 in meson.build.
- 12444183e401 19 (unreleased) landed
-
pg_plan_advice: Avoid a crash under GEQO.
- 01b02c0ecad1 19 (unreleased) landed
-
Test pg_plan_advice using a new test_plan_advice module.
- e0e4c132ef2b 19 (unreleased) landed
-
pg_plan_advice: Always install pg_plan_advice.h, and in the right place
- 59dcc19b397f 19 (unreleased) landed
-
pg_plan_advice: Fix failures to accept identifier keywords.
- 5e72ce2467c1 19 (unreleased) landed
-
Add pg_plan_advice contrib module.
- 5883ff30b02c 19 (unreleased) landed
-
Allow extensions to mark an individual index as disabled.
- 0fbfd37cefb7 19 (unreleased) landed
-
Replace get_relation_info_hook with build_simple_rel_hook.
- 91f33a2ae92a 19 (unreleased) landed
-
Store information about Append node consolidation in the final plan.
- 7358abcc6076 19 (unreleased) landed
-
Store information about elided nodes in the final plan.
- 0d4391b265f8 19 (unreleased) landed
-
Store information about range-table flattening in the final plan.
- adbad833f3d9 19 (unreleased) landed
-
Pass cursorOptions to planner_setup_hook.
- 0f4c8d33d49d 19 (unreleased) landed
-
Fix PGS_CONSIDER_NONPARTIAL interaction with Materialize nodes.
- cbdf93d47122 19 (unreleased) landed
-
Fix mistakes in commit 4020b370f214315b8c10430301898ac21658143f
- 71c1136989b3 19 (unreleased) landed
-
Allow for plugin control over path generation strategies.
- 4020b370f214 19 (unreleased) landed
-
Update some comments for fasthash
- 7892e2592471 19 (unreleased) landed
-
Allow passing a pointer to GetNamedDSMSegment()'s init callback.
- 48d4a1423d2e 19 (unreleased) cited
-
Don't reset the pathlist of partitioned joinrels.
- 014f9a831a32 19 (unreleased) cited
-
Treat number of disabled nodes in a path as a separate cost metric.
- e22253467942 18.0 cited