Re: Fwd: pg18 bug? SELECT query doesn't work - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Fwd: pg18 bug? SELECT query doesn't work
Date
Msg-id 1752324.1767805242@sss.pgh.pa.us
Whole thread Raw
In response to Re: Fwd: pg18 bug? SELECT query doesn't work  (Richard Guo <guofenglinux@gmail.com>)
Responses Re: Fwd: pg18 bug? SELECT query doesn't work
List pgsql-hackers
Richard Guo <guofenglinux@gmail.com> writes:
> On Wed, Jan 7, 2026 at 11:37 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I'm also wondering (don't recall the details of your patch)
>> whether you are repeating eval_const_expressions after
>> grouping-Var expansion.  If not, there are going to be bugs
>> there, like failure to handle named args in function calls.
>> That could be another reason to make this happen earlier.

> Currently we're not repeating eval_const_expressions after the
> grouping-Var expansion, but I fail to wrap my head around why that
> would be a problem.

What I was mainly concerned about was whether the replacement
expressions ever got passed through eval_const_expressions().
I see now that they do, at planner.c:1069.

It's still not really desirable that this is done separately;
for example, I think it breaks the assumption that we will have
AND/OR flatness everywhere.  But I think that only leads to
possible inefficiencies not wrong answers.  And I do take your
point about needing to preserve the separate identities of
these subexpressions.  So let's let that go for now.

The main problem, as you say, is that allpaths.c is coming to
conclusions about the contents of output expressions of the
subquery without having done any of this.  The only really
simple answer I can see is to make a copy of the subquery's
tlist and apply these transformations to it before we run
the subquery_is_pushdown_safe logic.  That's ... ugly.

Perhaps another idea could be to shove the responsibility for this
down into subquery_planner (or make it call a callback at the right
point), and handle transferring of parent restriction clauses into
HAVING only after we've finished preprocessing the subquery's tlist.
That's an uncomfortably big change to be making in a released branch,
but it might still be a better way than duplicating preprocessing.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Sami Imseih
Date:
Subject: Re: Logging parallel worker draught
Next
From: Peter Geoghegan
Date:
Subject: Re: Fix comments on _bt_skiparray_strat_increment/decrement