| From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
|---|---|
| To: | Lukas Fittl <lukas(at)fittl(dot)com> |
| Cc: | Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>, Dian Fay <di(at)nmfay(dot)com>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: pg_plan_advice |
| Date: | 2026-01-28 17:13:39 |
| Message-ID: | CA+TgmoaZMOikxK=LqS+Jn+835h9S139JLGk-3LyETVXw5W5j=w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Mon, Jan 12, 2026 at 12:13 PM Robert Haas <robertmhaas(at)gmail(dot)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
| Attachment | Content-Type | Size |
|---|---|---|
| v13-0001-Store-information-about-range-table-flattening-i.patch | application/octet-stream | 7.8 KB |
| v13-0002-Store-information-about-elided-nodes-in-the-fina.patch | application/octet-stream | 9.8 KB |
| v13-0003-Store-information-about-Append-node-consolidatio.patch | application/octet-stream | 40.5 KB |
| v13-0004-Add-pg_plan_advice-contrib-module.patch | application/octet-stream | 477.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hannu Krosing | 2026-01-28 17:29:58 | Re: Patch: dumping tables data in multiple chunks in pg_dump |
| Previous Message | Marco Nenciarini | 2026-01-28 17:03:24 | BUG: Cascading standby fails to reconnect after falling back to archive recovery |