pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u 4+ messages / 1 participants [nested] [flat]
* pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u @ 2022-08-27 16:11 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2022-08-27 16:11 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited updates. Prior to v14, if we have a MULTIEXPR SubPlan (that is, use of the syntax UPDATE ... SET (c1, ...) = (SELECT ...)) in an UPDATE with an inherited or partitioned target table, inheritance_planner() will clone the targetlist and therefore also the MULTIEXPR SubPlan and the Param nodes referencing it for each child target table. Up to now, we've allowed all the clones to share the underlying subplan as well as the output parameter IDs -- that is, the runtime ParamExecData slots. That technique is borrowed from the far older code that supports initplans, and it works okay in that case because the cloned SubPlan nodes are essentially identical. So it doesn't matter which one of the clones the shared ParamExecData.execPlan field might point to. However, this fails to hold for MULTIEXPR SubPlans, because they can have nonempty "args" lists (values to be passed into the subplan), and those lists could get mutated to different states in the various clones. In the submitted reproducer, as well as the test case added here, one clone contains Vars with varno OUTER_VAR where another has INNER_VAR, because the child tables are respectively on the outer or inner side of the join. Sharing the execPlan pointer can result in trying to evaluate an args list that doesn't match the local execution state, with mayhem ensuing. The result often is to trigger consistency checks in the executor, but I believe this could end in a crash or incorrect updates. To fix, assign new Param IDs to each of the cloned SubPlans, so that they don't share ParamExecData slots at runtime. It still seems fine for the clones to share the underlying subplan, and extra ParamExecData slots are cheap enough that this fix shouldn't cost much. This has been busted since we invented MULTIEXPR SubPlans in 9.5. Probably the lack of previous reports is because query plans in which the different clones of a MULTIEXPR mutate to effectively-different states are pretty rare. There's no issue in v14 and later, because without inheritance_planner() there's never a reason to clone MULTIEXPR SubPlans. Per bug #17596 from Andre Lin. Patch v10-v13 only. Discussion: https://postgr.es/m/17596-c5357f61427a81dc@postgresql.org Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f8e70cfb8fd48e857d88f7ca1305ff69b25f13a3 Modified Files -------------- src/backend/executor/nodeSubplan.c | 15 ++++++ src/backend/optimizer/plan/planner.c | 4 ++ src/backend/optimizer/plan/subselect.c | 95 ++++++++++++++++++++++++++++++++++ src/include/optimizer/subselect.h | 1 + src/test/regress/expected/inherit.out | 49 ++++++++++++++++++ src/test/regress/sql/inherit.sql | 20 +++++++ 6 files changed, 184 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u @ 2022-08-27 16:11 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2022-08-27 16:11 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited updates. Prior to v14, if we have a MULTIEXPR SubPlan (that is, use of the syntax UPDATE ... SET (c1, ...) = (SELECT ...)) in an UPDATE with an inherited or partitioned target table, inheritance_planner() will clone the targetlist and therefore also the MULTIEXPR SubPlan and the Param nodes referencing it for each child target table. Up to now, we've allowed all the clones to share the underlying subplan as well as the output parameter IDs -- that is, the runtime ParamExecData slots. That technique is borrowed from the far older code that supports initplans, and it works okay in that case because the cloned SubPlan nodes are essentially identical. So it doesn't matter which one of the clones the shared ParamExecData.execPlan field might point to. However, this fails to hold for MULTIEXPR SubPlans, because they can have nonempty "args" lists (values to be passed into the subplan), and those lists could get mutated to different states in the various clones. In the submitted reproducer, as well as the test case added here, one clone contains Vars with varno OUTER_VAR where another has INNER_VAR, because the child tables are respectively on the outer or inner side of the join. Sharing the execPlan pointer can result in trying to evaluate an args list that doesn't match the local execution state, with mayhem ensuing. The result often is to trigger consistency checks in the executor, but I believe this could end in a crash or incorrect updates. To fix, assign new Param IDs to each of the cloned SubPlans, so that they don't share ParamExecData slots at runtime. It still seems fine for the clones to share the underlying subplan, and extra ParamExecData slots are cheap enough that this fix shouldn't cost much. This has been busted since we invented MULTIEXPR SubPlans in 9.5. Probably the lack of previous reports is because query plans in which the different clones of a MULTIEXPR mutate to effectively-different states are pretty rare. There's no issue in v14 and later, because without inheritance_planner() there's never a reason to clone MULTIEXPR SubPlans. Per bug #17596 from Andre Lin. Patch v10-v13 only. Discussion: https://postgr.es/m/17596-c5357f61427a81dc@postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d9ebc582fbc64e30e2e2b4543147d21e42b7e15f Modified Files -------------- src/backend/executor/nodeSubplan.c | 15 ++++++ src/backend/optimizer/plan/planner.c | 4 ++ src/backend/optimizer/plan/subselect.c | 95 ++++++++++++++++++++++++++++++++++ src/include/optimizer/subselect.h | 1 + src/test/regress/expected/inherit.out | 49 ++++++++++++++++++ src/test/regress/sql/inherit.sql | 20 +++++++ 6 files changed, 184 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u @ 2022-08-27 16:11 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2022-08-27 16:11 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited updates. Prior to v14, if we have a MULTIEXPR SubPlan (that is, use of the syntax UPDATE ... SET (c1, ...) = (SELECT ...)) in an UPDATE with an inherited or partitioned target table, inheritance_planner() will clone the targetlist and therefore also the MULTIEXPR SubPlan and the Param nodes referencing it for each child target table. Up to now, we've allowed all the clones to share the underlying subplan as well as the output parameter IDs -- that is, the runtime ParamExecData slots. That technique is borrowed from the far older code that supports initplans, and it works okay in that case because the cloned SubPlan nodes are essentially identical. So it doesn't matter which one of the clones the shared ParamExecData.execPlan field might point to. However, this fails to hold for MULTIEXPR SubPlans, because they can have nonempty "args" lists (values to be passed into the subplan), and those lists could get mutated to different states in the various clones. In the submitted reproducer, as well as the test case added here, one clone contains Vars with varno OUTER_VAR where another has INNER_VAR, because the child tables are respectively on the outer or inner side of the join. Sharing the execPlan pointer can result in trying to evaluate an args list that doesn't match the local execution state, with mayhem ensuing. The result often is to trigger consistency checks in the executor, but I believe this could end in a crash or incorrect updates. To fix, assign new Param IDs to each of the cloned SubPlans, so that they don't share ParamExecData slots at runtime. It still seems fine for the clones to share the underlying subplan, and extra ParamExecData slots are cheap enough that this fix shouldn't cost much. This has been busted since we invented MULTIEXPR SubPlans in 9.5. Probably the lack of previous reports is because query plans in which the different clones of a MULTIEXPR mutate to effectively-different states are pretty rare. There's no issue in v14 and later, because without inheritance_planner() there's never a reason to clone MULTIEXPR SubPlans. Per bug #17596 from Andre Lin. Patch v10-v13 only. Discussion: https://postgr.es/m/17596-c5357f61427a81dc@postgresql.org Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3f7323cbbdd3fddc54619b8bd0e0b03a27befdfc Modified Files -------------- src/backend/executor/nodeSubplan.c | 15 ++++++ src/backend/optimizer/plan/planner.c | 4 ++ src/backend/optimizer/plan/subselect.c | 95 ++++++++++++++++++++++++++++++++++ src/include/optimizer/subselect.h | 1 + src/test/regress/expected/inherit.out | 49 ++++++++++++++++++ src/test/regress/sql/inherit.sql | 20 +++++++ 6 files changed, 184 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u @ 2022-08-27 16:11 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2022-08-27 16:11 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited updates. Prior to v14, if we have a MULTIEXPR SubPlan (that is, use of the syntax UPDATE ... SET (c1, ...) = (SELECT ...)) in an UPDATE with an inherited or partitioned target table, inheritance_planner() will clone the targetlist and therefore also the MULTIEXPR SubPlan and the Param nodes referencing it for each child target table. Up to now, we've allowed all the clones to share the underlying subplan as well as the output parameter IDs -- that is, the runtime ParamExecData slots. That technique is borrowed from the far older code that supports initplans, and it works okay in that case because the cloned SubPlan nodes are essentially identical. So it doesn't matter which one of the clones the shared ParamExecData.execPlan field might point to. However, this fails to hold for MULTIEXPR SubPlans, because they can have nonempty "args" lists (values to be passed into the subplan), and those lists could get mutated to different states in the various clones. In the submitted reproducer, as well as the test case added here, one clone contains Vars with varno OUTER_VAR where another has INNER_VAR, because the child tables are respectively on the outer or inner side of the join. Sharing the execPlan pointer can result in trying to evaluate an args list that doesn't match the local execution state, with mayhem ensuing. The result often is to trigger consistency checks in the executor, but I believe this could end in a crash or incorrect updates. To fix, assign new Param IDs to each of the cloned SubPlans, so that they don't share ParamExecData slots at runtime. It still seems fine for the clones to share the underlying subplan, and extra ParamExecData slots are cheap enough that this fix shouldn't cost much. This has been busted since we invented MULTIEXPR SubPlans in 9.5. Probably the lack of previous reports is because query plans in which the different clones of a MULTIEXPR mutate to effectively-different states are pretty rare. There's no issue in v14 and later, because without inheritance_planner() there's never a reason to clone MULTIEXPR SubPlans. Per bug #17596 from Andre Lin. Patch v10-v13 only. Discussion: https://postgr.es/m/17596-c5357f61427a81dc@postgresql.org Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e1ea6f37452ac6869f12b8c871e3752e8e00243d Modified Files -------------- src/backend/executor/nodeSubplan.c | 15 ++++++ src/backend/optimizer/plan/planner.c | 4 ++ src/backend/optimizer/plan/subselect.c | 95 ++++++++++++++++++++++++++++++++++ src/include/optimizer/subselect.h | 1 + src/test/regress/expected/inherit.out | 49 ++++++++++++++++++ src/test/regress/sql/inherit.sql | 20 +++++++ 6 files changed, 184 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2022-08-27 16:11 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2022-08-27 16:11 pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u Tom Lane <tgl@sss.pgh.pa.us> 2022-08-27 16:11 pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u Tom Lane <tgl@sss.pgh.pa.us> 2022-08-27 16:11 pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u Tom Lane <tgl@sss.pgh.pa.us> 2022-08-27 16:11 pgsql: Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited u Tom Lane <tgl@sss.pgh.pa.us>
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