Re: Fwd: pg18 bug? SELECT query doesn't work

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Eric Ridge <eebbrr(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fwd: pg18 bug? SELECT query doesn't work
Date: 2026-01-07 17:00:42
Message-ID: 1752324.1767805242@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Richard Guo <guofenglinux(at)gmail(dot)com> writes:
> On Wed, Jan 7, 2026 at 11:37 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stuart Campbell 2026-01-07 21:55:50 Re: Unexpected modification of check constraint definition
Previous Message Adrian Klaver 2026-01-07 15:24:13 Re: Unexpected modification of check constraint definition

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2026-01-07 17:54:49 Re: Fix comments on _bt_skiparray_strat_increment/decrement
Previous Message Sami Imseih 2026-01-07 16:47:37 Re: Logging parallel worker draught