From a7f107df2b700c859e4d9ad2ca66b07a465d6223 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 31 Jul 2024 18:11:49 -0700 Subject: Evaluate arguments of correlated SubPlans in the referencing ExprState Until now we generated an ExprState for each parameter to a SubPlan and evaluated them one-by-one ExecScanSubPlan. That's sub-optimal as creating lots of small ExprStates a) makes JIT compilation more expensive b) wastes memory c) is a bit slower to execute This commit arranges to evaluate parameters to a SubPlan as part of the ExprState referencing a SubPlan, using the new EEOP_PARAM_SET expression step. We emit one EEOP_PARAM_SET for each argument to a subplan, just before the EEOP_SUBPLAN step. It likely is worth using EEOP_PARAM_SET in other places as well, e.g. for SubPlan outputs, nestloop parameters and - more ambitiously - to get rid of ExprContext->domainValue/caseValue/ecxt_agg*. But that's for later. Author: Andres Freund Reviewed-by: Tom Lane Reviewed-by: Alena Rybakina Discussion: https://postgr.es/m/20230225214401.346ancgjqc3zmvek@awork3.anarazel.de --- src/backend/executor/execProcnode.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/backend/executor/execProcnode.c') diff --git a/src/backend/executor/execProcnode.c b/src/backend/executor/execProcnode.c index 6e48062f56a..34f28dfecea 100644 --- a/src/backend/executor/execProcnode.c +++ b/src/backend/executor/execProcnode.c @@ -393,6 +393,10 @@ ExecInitNode(Plan *node, EState *estate, int eflags) /* * Initialize any initPlans present in this node. The planner put them in * a separate list for us. + * + * The defining characteristic of initplans is that they don't have + * arguments, so we don't need to evaluate them (in contrast to + * ExecInitSubPlanExpr()). */ subps = NIL; foreach(l, node->initPlan) @@ -401,6 +405,7 @@ ExecInitNode(Plan *node, EState *estate, int eflags) SubPlanState *sstate; Assert(IsA(subplan, SubPlan)); + Assert(subplan->args == NIL); sstate = ExecInitSubPlan(subplan, result); subps = lappend(subps, sstate); } -- cgit v1.2.3