Re: Fwd: pg18 bug? SELECT query doesn't work
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Guo <guofenglinux@gmail.com>
Cc: Eric Ridge <eebbrr@gmail.com>,
Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-01-07T17:00:42Z
Lists: pgsql-hackers, pgsql-general
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
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix unsafe pushdown of quals referencing grouping Vars
- 7650eabb662f 18.2 landed
- 34740b90bc12 19 (unreleased) landed
-
Introduce an RTE for the grouping step
- 247dea89f761 18.0 cited