pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix stale initplans after removing a plan level in setrefs.c
6+ messages / 1 participants
[nested] [flat]

* pgsql: Fix stale initplans after removing a plan level in setrefs.c
@ 2026-11-11 06:56  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Richard Guo @ 2026-11-11 06:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix stale initplans after removing a plan level in setrefs.c

When set_plan_references() removes a trivial SubqueryScan or a
single-child Append or MergeAppend, clean_up_removed_plan_level()
moves the removed node's initplans to its child.  However, the child's
extParam and allParam sets, which SS_finalize_plan() computed before
the move, do not include the Params those initplans depend on.  At
rescan, UpdateChangedParamSet() therefore does not propagate a change
in such a Param to the child, and the initplans are not re-evaluated,
so the child keeps using their stale output values, producing wrong
results.  This can happen, for example, with a lateral subquery that
scans only one partition of a partitioned table and whose scalar
sub-select references an outer column.

To fix, add the removed node's extParam and allParam sets into the
child's.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4_JzG96+RjzdEpRQ0-rWkuzU1cmj7xybpzFg6GYdGcE8Q@mail.gmail.com
Backpatch-through: 15

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9b80b3170b9c5be2f22540facea52f5e38915704

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c    |  8 ++++++++
src/test/regress/expected/subselect.out | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 17 +++++++++++++++++
3 files changed, 56 insertions(+)



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

* pgsql: Fix stale initplans after removing a plan level in setrefs.c
@ 2026-11-11 06:56  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Richard Guo @ 2026-11-11 06:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix stale initplans after removing a plan level in setrefs.c

When set_plan_references() removes a trivial SubqueryScan or a
single-child Append or MergeAppend, clean_up_removed_plan_level()
moves the removed node's initplans to its child.  However, the child's
extParam and allParam sets, which SS_finalize_plan() computed before
the move, do not include the Params those initplans depend on.  At
rescan, UpdateChangedParamSet() therefore does not propagate a change
in such a Param to the child, and the initplans are not re-evaluated,
so the child keeps using their stale output values, producing wrong
results.  This can happen, for example, with a lateral subquery that
scans only one partition of a partitioned table and whose scalar
sub-select references an outer column.

To fix, add the removed node's extParam and allParam sets into the
child's.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4_JzG96+RjzdEpRQ0-rWkuzU1cmj7xybpzFg6GYdGcE8Q@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4561af585ec2bb0a7aff7f809cc4ad1827209fd4

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c    |  8 ++++++++
src/test/regress/expected/subselect.out | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 17 +++++++++++++++++
3 files changed, 56 insertions(+)



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

* pgsql: Fix stale initplans after removing a plan level in setrefs.c
@ 2026-11-11 06:56  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Richard Guo @ 2026-11-11 06:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix stale initplans after removing a plan level in setrefs.c

When set_plan_references() removes a trivial SubqueryScan or a
single-child Append or MergeAppend, clean_up_removed_plan_level()
moves the removed node's initplans to its child.  However, the child's
extParam and allParam sets, which SS_finalize_plan() computed before
the move, do not include the Params those initplans depend on.  At
rescan, UpdateChangedParamSet() therefore does not propagate a change
in such a Param to the child, and the initplans are not re-evaluated,
so the child keeps using their stale output values, producing wrong
results.  This can happen, for example, with a lateral subquery that
scans only one partition of a partitioned table and whose scalar
sub-select references an outer column.

To fix, add the removed node's extParam and allParam sets into the
child's.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4_JzG96+RjzdEpRQ0-rWkuzU1cmj7xybpzFg6GYdGcE8Q@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/14f40eee873ed6d356a7ea4a0d812f670af2327c

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c    |  8 ++++++++
src/test/regress/expected/subselect.out | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 17 +++++++++++++++++
3 files changed, 56 insertions(+)



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

* pgsql: Fix stale initplans after removing a plan level in setrefs.c
@ 2026-11-11 06:56  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Richard Guo @ 2026-11-11 06:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix stale initplans after removing a plan level in setrefs.c

When set_plan_references() removes a trivial SubqueryScan or a
single-child Append or MergeAppend, clean_up_removed_plan_level()
moves the removed node's initplans to its child.  However, the child's
extParam and allParam sets, which SS_finalize_plan() computed before
the move, do not include the Params those initplans depend on.  At
rescan, UpdateChangedParamSet() therefore does not propagate a change
in such a Param to the child, and the initplans are not re-evaluated,
so the child keeps using their stale output values, producing wrong
results.  This can happen, for example, with a lateral subquery that
scans only one partition of a partitioned table and whose scalar
sub-select references an outer column.

To fix, add the removed node's extParam and allParam sets into the
child's.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4_JzG96+RjzdEpRQ0-rWkuzU1cmj7xybpzFg6GYdGcE8Q@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_17_STABLE

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

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c    |  8 ++++++++
src/test/regress/expected/subselect.out | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 17 +++++++++++++++++
3 files changed, 56 insertions(+)



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

* pgsql: Fix stale initplans after removing a plan level in setrefs.c
@ 2026-11-11 06:56  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Richard Guo @ 2026-11-11 06:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix stale initplans after removing a plan level in setrefs.c

When set_plan_references() removes a trivial SubqueryScan or a
single-child Append or MergeAppend, clean_up_removed_plan_level()
moves the removed node's initplans to its child.  However, the child's
extParam and allParam sets, which SS_finalize_plan() computed before
the move, do not include the Params those initplans depend on.  At
rescan, UpdateChangedParamSet() therefore does not propagate a change
in such a Param to the child, and the initplans are not re-evaluated,
so the child keeps using their stale output values, producing wrong
results.  This can happen, for example, with a lateral subquery that
scans only one partition of a partitioned table and whose scalar
sub-select references an outer column.

To fix, add the removed node's extParam and allParam sets into the
child's.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4_JzG96+RjzdEpRQ0-rWkuzU1cmj7xybpzFg6GYdGcE8Q@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5a6d609515ae390d6147900ec9299ac51e8f1477

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c    | 11 +++++++++++
src/test/regress/expected/subselect.out | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 17 +++++++++++++++++
3 files changed, 59 insertions(+)



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

* pgsql: Fix stale initplans after removing a plan level in setrefs.c
@ 2026-11-11 06:56  Richard Guo <rguo@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Richard Guo @ 2026-11-11 06:56 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix stale initplans after removing a plan level in setrefs.c

When set_plan_references() removes a trivial SubqueryScan or a
single-child Append or MergeAppend, clean_up_removed_plan_level()
moves the removed node's initplans to its child.  However, the child's
extParam and allParam sets, which SS_finalize_plan() computed before
the move, do not include the Params those initplans depend on.  At
rescan, UpdateChangedParamSet() therefore does not propagate a change
in such a Param to the child, and the initplans are not re-evaluated,
so the child keeps using their stale output values, producing wrong
results.  This can happen, for example, with a lateral subquery that
scans only one partition of a partitioned table and whose scalar
sub-select references an outer column.

To fix, add the removed node's extParam and allParam sets into the
child's.

Back-patch to all supported branches.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAMbWs4_JzG96+RjzdEpRQ0-rWkuzU1cmj7xybpzFg6GYdGcE8Q@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/39ed14841cd3e470e4fee2289e0f77b53beec772

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c    | 11 +++++++++++
src/test/regress/expected/subselect.out | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql      | 17 +++++++++++++++++
3 files changed, 59 insertions(+)



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


end of thread, other threads:[~2026-11-11 06:56 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 06:56 pgsql: Fix stale initplans after removing a plan level in setrefs.c Richard Guo <rguo@postgresql.org>
2026-11-11 06:56 pgsql: Fix stale initplans after removing a plan level in setrefs.c Richard Guo <rguo@postgresql.org>
2026-11-11 06:56 pgsql: Fix stale initplans after removing a plan level in setrefs.c Richard Guo <rguo@postgresql.org>
2026-11-11 06:56 pgsql: Fix stale initplans after removing a plan level in setrefs.c Richard Guo <rguo@postgresql.org>
2026-11-11 06:56 pgsql: Fix stale initplans after removing a plan level in setrefs.c Richard Guo <rguo@postgresql.org>
2026-11-11 06:56 pgsql: Fix stale initplans after removing a plan level in setrefs.c 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