From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
---|---|
To: | Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Wrong results with subquery pullup and grouping sets |
Date: | 2025-03-05 09:09:05 |
Message-ID: | CAMbWs4-VXDEi1v+hZYLxpOv0riJxHsCkCH1f46tLnhonEAyGCQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Mar 5, 2025 at 11:02 AM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> It seems to me that simple Var expressions in a subquery's target list
> also need to retain their separate identity in order to match grouping
> set columns after subquery pullup, not just non-var expressions.
I noticed the adjacent code that sets wrap_non_vars to true if we
are considering an appendrel child subquery, and I doubt this is
necessary.
/*
* If we are dealing with an appendrel member then anything that's not a
* simple Var has to be turned into a PlaceHolderVar. We force this to
* ensure that what we pull up doesn't get merged into a surrounding
* expression during later processing and then fail to match the
* expression actually available from the appendrel.
*/
if (containing_appendrel != NULL)
rvcontext.wrap_non_vars = true;
As explained in e42e31243, the only part of the upper query that could
reference the appendrel child yet is the translated_vars list of the
associated AppendRelInfo that we just made for this child, and we do
not want to force use of PHVs in the AppendRelInfo (see the comment in
perform_pullup_replace_vars). In fact, perform_pullup_replace_vars
sets wrap_non_vars to false before performing pullup_replace_vars on
the AppendRelInfo. It seems to me that this makes the code shown
above unnecessary, and we can simply remove it.
Any thoughts?
Thanks
Richard
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2025-03-05 09:12:15 | Re: Add contrib/pg_logicalsnapinspect |
Previous Message | Hayato Kuroda (Fujitsu) | 2025-03-05 09:05:25 | RE: Selectively invalidate caches in pgoutput module |