pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix nestloop parameter assignment for PHVs evaluated above outer
3+ messages / 1 participants
[nested] [flat]

* pgsql: Fix nestloop parameter assignment for PHVs evaluated above outer
@ 2026-10-30 01:51  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Richard Guo @ 2026-10-30 01:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix nestloop parameter assignment for PHVs evaluated above outer joins

A NestLoop can supply a PlaceHolderVar as a parameter if the PHV can
be evaluated from the lefthand rels plus the required-outer rels of
the join.  A PHV's ph_eval_at can include outer-join relids, but
required-outer sets need not: create_lateral_join_info() keeps
outer-join relids out of the lateral dependencies it derives from
ph_lateral.  So when an outer join within ph_eval_at had been computed
by an enclosing nestloop's outer side, the test in
identify_current_nestloop_params() failed and no plan node claimed the
parameter.  This resulted in "failed to assign all NestLoopParams to
plan nodes", or, if an unrelated upper NestLoop happened to cover
ph_eval_at and claimed the parameter, "plan should not reference
subplan's variable".

To fix, have create_nestloop_plan() also count the outer joins that
have already been computed by the outer rels in scope.

Back-patch to v18, where commit a16ef313f made it possible to compute
a PHV that is used as a nestloop parameter in the outer side of the
NestLoop.  v16 and v17 can fail the same way, since ph_eval_at has
included outer-join relids since v16, but they lack that machinery.
Fixing them would mean adding join-order restrictions to
have_dangerous_phv() that could change plans that work today, which
does not seem worth the risk for a failure this unlikely.

Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4-fcAULTpWthZMHGOFK1J+Hz=Dvr1TO-M20cC317rOGOA@mail.gmail.com
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c1c930376854dda25ce07a74d34d1a16f91cd3aa

Modified Files
--------------
src/backend/optimizer/plan/createplan.c |  9 ++++++
src/test/regress/expected/join.out      | 53 +++++++++++++++++++++++++++++++++
src/test/regress/sql/join.sql           | 18 +++++++++++
3 files changed, 80 insertions(+)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix nestloop parameter assignment for PHVs evaluated above outer
@ 2026-10-30 01:51  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Richard Guo @ 2026-10-30 01:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix nestloop parameter assignment for PHVs evaluated above outer joins

A NestLoop can supply a PlaceHolderVar as a parameter if the PHV can
be evaluated from the lefthand rels plus the required-outer rels of
the join.  A PHV's ph_eval_at can include outer-join relids, but
required-outer sets need not: create_lateral_join_info() keeps
outer-join relids out of the lateral dependencies it derives from
ph_lateral.  So when an outer join within ph_eval_at had been computed
by an enclosing nestloop's outer side, the test in
identify_current_nestloop_params() failed and no plan node claimed the
parameter.  This resulted in "failed to assign all NestLoopParams to
plan nodes", or, if an unrelated upper NestLoop happened to cover
ph_eval_at and claimed the parameter, "plan should not reference
subplan's variable".

To fix, have create_nestloop_plan() also count the outer joins that
have already been computed by the outer rels in scope.

Back-patch to v18, where commit a16ef313f made it possible to compute
a PHV that is used as a nestloop parameter in the outer side of the
NestLoop.  v16 and v17 can fail the same way, since ph_eval_at has
included outer-join relids since v16, but they lack that machinery.
Fixing them would mean adding join-order restrictions to
have_dangerous_phv() that could change plans that work today, which
does not seem worth the risk for a failure this unlikely.

Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4-fcAULTpWthZMHGOFK1J+Hz=Dvr1TO-M20cC317rOGOA@mail.gmail.com
Backpatch-through: 18

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d1e045baf82f26fa0ae0bd4bd2bc09cd1081b4fd

Modified Files
--------------
src/backend/optimizer/plan/createplan.c |  9 ++++++
src/test/regress/expected/join.out      | 53 +++++++++++++++++++++++++++++++++
src/test/regress/sql/join.sql           | 18 +++++++++++
3 files changed, 80 insertions(+)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix nestloop parameter assignment for PHVs evaluated above outer
@ 2026-10-30 01:51  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Richard Guo @ 2026-10-30 01:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix nestloop parameter assignment for PHVs evaluated above outer joins

A NestLoop can supply a PlaceHolderVar as a parameter if the PHV can
be evaluated from the lefthand rels plus the required-outer rels of
the join.  A PHV's ph_eval_at can include outer-join relids, but
required-outer sets need not: create_lateral_join_info() keeps
outer-join relids out of the lateral dependencies it derives from
ph_lateral.  So when an outer join within ph_eval_at had been computed
by an enclosing nestloop's outer side, the test in
identify_current_nestloop_params() failed and no plan node claimed the
parameter.  This resulted in "failed to assign all NestLoopParams to
plan nodes", or, if an unrelated upper NestLoop happened to cover
ph_eval_at and claimed the parameter, "plan should not reference
subplan's variable".

To fix, have create_nestloop_plan() also count the outer joins that
have already been computed by the outer rels in scope.

Back-patch to v18, where commit a16ef313f made it possible to compute
a PHV that is used as a nestloop parameter in the outer side of the
NestLoop.  v16 and v17 can fail the same way, since ph_eval_at has
included outer-join relids since v16, but they lack that machinery.
Fixing them would mean adding join-order restrictions to
have_dangerous_phv() that could change plans that work today, which
does not seem worth the risk for a failure this unlikely.

Author: Richard Guo <guofenglinux@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4-fcAULTpWthZMHGOFK1J+Hz=Dvr1TO-M20cC317rOGOA@mail.gmail.com
Backpatch-through: 18

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e84fb3f1c9c25867739580470bec48b19f18081d

Modified Files
--------------
src/backend/optimizer/plan/createplan.c |  9 ++++++
src/test/regress/expected/join.out      | 53 +++++++++++++++++++++++++++++++++
src/test/regress/sql/join.sql           | 18 +++++++++++
3 files changed, 80 insertions(+)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-10-30 01:51 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-30 01:51 pgsql: Fix nestloop parameter assignment for PHVs evaluated above outer Richard Guo <rguo@postgresql.org>
2026-10-30 01:51 pgsql: Fix nestloop parameter assignment for PHVs evaluated above outer Richard Guo <rguo@postgresql.org>
2026-10-30 01:51 pgsql: Fix nestloop parameter assignment for PHVs evaluated above outer Richard Guo <rguo@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox