pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Don't use SubPlan-containing expressions for startup-time prunin 3+ messages / 1 participants [nested] [flat]
* pgsql: Don't use SubPlan-containing expressions for startup-time prunin @ 2026-10-14 05:56 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: Richard Guo @ 2026-10-14 05:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't use SubPlan-containing expressions for startup-time pruning match_clause_to_partition_key() tells whether a comparison value can be evaluated during executor-startup pruning by checking that it has no Vars, no volatile functions and no PARAM_EXEC Params. A SubPlan normally fails the last test, since the testexpr of an ANY/ALL SubPlan references the subplan's output Params. But if the left-hand side is a NULL constant, the strict comparison operator in the testexpr is const-folded to a NULL Const, and an uncorrelated SubPlan has no parParam or args either, so nothing is left for pull_exec_paramids() to find. The expression then reaches initial_pruning_steps, where ExecDoInitialPruning() must evaluate it before any PlanState exists, and we fail with "SubPlan found with no parent plan". To fix, don't allow such an expression to be used for startup-time pruning. It's still fine for per-scan pruning, which has a PlanState to evaluate it with. Expressions containing exec Params are unaffected. This has been broken since d47cbf474, which moved initial pruning out of ExecInitNode(); before that, pruning always had the parent node's PlanState available. Back-patch to v18. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Amit Langote <amitlangote09@gmail.com> Discussion: https://postgr.es/m/CAMbWs48nYDu7joYeyMKYdX8kHoL_ASEax2fqZH6L+HHqO2nkXA@mail.gmail.com Backpatch-through: 18 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/eacee6b618718f9e5298df0629d9720fa4dd5e45 Modified Files -------------- src/backend/partitioning/partprune.c | 12 +++++++++++- src/test/regress/expected/partition_prune.out | 16 ++++++++++++++++ src/test/regress/sql/partition_prune.sql | 6 ++++++ 3 files changed, 33 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Don't use SubPlan-containing expressions for startup-time prunin @ 2026-10-14 05:56 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: Richard Guo @ 2026-10-14 05:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't use SubPlan-containing expressions for startup-time pruning match_clause_to_partition_key() tells whether a comparison value can be evaluated during executor-startup pruning by checking that it has no Vars, no volatile functions and no PARAM_EXEC Params. A SubPlan normally fails the last test, since the testexpr of an ANY/ALL SubPlan references the subplan's output Params. But if the left-hand side is a NULL constant, the strict comparison operator in the testexpr is const-folded to a NULL Const, and an uncorrelated SubPlan has no parParam or args either, so nothing is left for pull_exec_paramids() to find. The expression then reaches initial_pruning_steps, where ExecDoInitialPruning() must evaluate it before any PlanState exists, and we fail with "SubPlan found with no parent plan". To fix, don't allow such an expression to be used for startup-time pruning. It's still fine for per-scan pruning, which has a PlanState to evaluate it with. Expressions containing exec Params are unaffected. This has been broken since d47cbf474, which moved initial pruning out of ExecInitNode(); before that, pruning always had the parent node's PlanState available. Back-patch to v18. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Amit Langote <amitlangote09@gmail.com> Discussion: https://postgr.es/m/CAMbWs48nYDu7joYeyMKYdX8kHoL_ASEax2fqZH6L+HHqO2nkXA@mail.gmail.com Backpatch-through: 18 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/3f807d6e9ee6dd1c4c717a8946b0f9b0133a16d8 Modified Files -------------- src/backend/partitioning/partprune.c | 12 +++++++++++- src/test/regress/expected/partition_prune.out | 16 ++++++++++++++++ src/test/regress/sql/partition_prune.sql | 6 ++++++ 3 files changed, 33 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Don't use SubPlan-containing expressions for startup-time prunin @ 2026-10-14 05:56 Richard Guo <rguo@postgresql.org> 0 siblings, 0 replies; 3+ messages in thread From: Richard Guo @ 2026-10-14 05:56 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Don't use SubPlan-containing expressions for startup-time pruning match_clause_to_partition_key() tells whether a comparison value can be evaluated during executor-startup pruning by checking that it has no Vars, no volatile functions and no PARAM_EXEC Params. A SubPlan normally fails the last test, since the testexpr of an ANY/ALL SubPlan references the subplan's output Params. But if the left-hand side is a NULL constant, the strict comparison operator in the testexpr is const-folded to a NULL Const, and an uncorrelated SubPlan has no parParam or args either, so nothing is left for pull_exec_paramids() to find. The expression then reaches initial_pruning_steps, where ExecDoInitialPruning() must evaluate it before any PlanState exists, and we fail with "SubPlan found with no parent plan". To fix, don't allow such an expression to be used for startup-time pruning. It's still fine for per-scan pruning, which has a PlanState to evaluate it with. Expressions containing exec Params are unaffected. This has been broken since d47cbf474, which moved initial pruning out of ExecInitNode(); before that, pruning always had the parent node's PlanState available. Back-patch to v18. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Amit Langote <amitlangote09@gmail.com> Discussion: https://postgr.es/m/CAMbWs48nYDu7joYeyMKYdX8kHoL_ASEax2fqZH6L+HHqO2nkXA@mail.gmail.com Backpatch-through: 18 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/70ffc30e12b1de43d6160682fc44c78b8de00f24 Modified Files -------------- src/backend/partitioning/partprune.c | 12 +++++++++++- src/test/regress/expected/partition_prune.out | 16 ++++++++++++++++ src/test/regress/sql/partition_prune.sql | 6 ++++++ 3 files changed, 33 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-10-14 05:56 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-14 05:56 pgsql: Don't use SubPlan-containing expressions for startup-time prunin Richard Guo <rguo@postgresql.org> 2026-10-14 05:56 pgsql: Don't use SubPlan-containing expressions for startup-time prunin Richard Guo <rguo@postgresql.org> 2026-10-14 05:56 pgsql: Don't use SubPlan-containing expressions for startup-time prunin 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