Re: Fwd: pg18 bug? SELECT query doesn't work
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Eric Ridge <eebbrr@gmail.com>,
Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-01-08T03:23:36Z
Lists: pgsql-hackers, pgsql-general
On Thu, Jan 8, 2026 at 2:00 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: > 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. It seems that allpaths.c checks the subquery's output only for two specific cases: to determine if it contains SRFs or volatile functions. Because of this, it seems that we don't need to apply the full set of transformations to it. We only need to account for join alias Vars and grouping Vars, as these can hide underlying expressions. The underlying expression of a join alias Var can only be a Var (potentially coerced) from one of the join's input rels, or a COALESCE expression containing the two input Vars. Therefore, it should not be able to contain SRFs or volatile functions, and thus we do not need to expand it beforehand. (This also answers my previous question about whether the current bug exists for join alias Vars.) Therefore, it seems to me that we only need to expand the grouping Vars beforehand when checking the subquery's output, as in the changes I proposed earlier. It's still ugly, but less so I think. > 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. Agreed. I think this is the theoretically correct way to handle the push-down of a subquery's restriction clauses. However, it seems like a non-trivial project, and it seems to require changing the signature of subquery_planner(), as we'd need to pass the subquery's RTE and RelOptInfo into it. So this looks too risky for stable branches. But maybe we can do that in dev branch. - Richard
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