1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00
Files
postgres/src/tools
Richard Guo 37b6e2657c Fix stale copies of PHVs in subqueries
When a subquery references an output of another subquery that gets
pulled up, and that output must be wrapped in a PlaceHolderVar because
of an intermediate outer join, the PHV expression is pushed down into
the subquery.  That copy is not preprocessed along with the outer
query's expressions, so the two copies can diverge.  This used to be
harmless, but since commit 2ebf25e7d join removal edits the whole
query tree, walking into subqueries, and can trip an assert in
ChangeVarNodes if it removes a rel whose Var survives only in such a
copy.

To fix, preprocess these copies at their owning query level, early in
subquery_planner, before anything can consume them (in particular
before SubLinks are turned into SubPlans).  This covers copies pushed
into both LATERAL subquery RTEs and SubLink subselects, and handles
nested copies innermost-first.  extract_lateral_references no longer
preprocesses the copies it pulls out.

Correspondingly, the subquery's own processing must leave the contents
of an upper-level PHV alone, since the owning level has already
preprocessed them: eval_const_expressions returns such a PHV
unchanged, and flatten_join_alias_vars no longer recurses into it.

Back-patch to v16, as with commit 2ebf25e7d.

Reported-by: Tender Wang <tndrwang@gmail.com>
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAHewXN=kWGAXV537mKtSyBYobGdHhYJVDJJMXXZEmmPWE_zaPw@mail.gmail.com
Backpatch-through: 16
2026-09-14 12:28:22 +09:00
..
2025-01-01 11:21:55 -05:00
2025-01-22 10:15:32 +09:00
…
…
2025-01-01 11:21:55 -05:00
2022-09-20 18:50:16 +02:00
2025-01-01 11:21:55 -05:00
2025-01-01 11:21:55 -05:00
2025-01-01 11:21:55 -05:00
2023-02-15 09:52:42 +09:00
…
2025-01-01 11:21:55 -05:00
2025-01-01 11:21:55 -05:00
2025-01-01 11:21:55 -05:00
2023-08-14 14:03:29 -04:00
2022-10-05 09:56:05 -07:00
2025-01-01 11:21:55 -05:00
2025-04-11 22:17:12 +02:00
2025-01-01 11:21:55 -05:00
2025-01-01 11:21:55 -05:00