aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-01-28 17:43:57 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-01-28 17:43:57 -0500
commit7c1719bc68ec1c347e7c80c3735bf3373e765f35 (patch)
tree347f18c3e52ef0cc406195b0c9f8720c347d30d1 /src/backend/executor/execMain.c
parent672614cf2137b2a3778c69de8d73770d84790e44 (diff)
downloadpostgresql-7c1719bc68ec1c347e7c80c3735bf3373e765f35.tar.gz
postgresql-7c1719bc68ec1c347e7c80c3735bf3373e765f35.zip
Fix handling of data-modifying CTE subplans in EvalPlanQual.
We can't just skip initializing such subplans, because the referencing CTE node will expect to find the subplan available when it initializes. That in turn means that ExecInitModifyTable must allow the case (which actually it needed to do anyway, since there's no guarantee that ModifyTable is exactly at the top of the CTE plan tree). So move the complaint about not being allowed in EvalPlanQual mode to execution instead of initialization. Testing turned up yet another problem, which is that we'd try to re-initialize the result relation's index list, leading to leaks and dangling pointers. Per report from Phil Sorber. Back-patch to 9.1 where data-modifying CTEs were introduced.
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r--src/backend/executor/execMain.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 422f737e82d..36dcc8e4b5d 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -2347,11 +2347,7 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
* ExecInitSubPlan expects to be able to find these entries. Some of the
* SubPlans might not be used in the part of the plan tree we intend to
* run, but since it's not easy to tell which, we just initialize them
- * all. (However, if the subplan is headed by a ModifyTable node, then it
- * must be a data-modifying CTE, which we will certainly not need to
- * re-run, so we can skip initializing it. This is just an efficiency
- * hack; it won't skip data-modifying CTEs for which the ModifyTable node
- * is not at the top.)
+ * all.
*/
Assert(estate->es_subplanstates == NIL);
foreach(l, parentestate->es_plannedstmt->subplans)
@@ -2359,12 +2355,7 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
Plan *subplan = (Plan *) lfirst(l);
PlanState *subplanstate;
- /* Don't initialize ModifyTable subplans, per comment above */
- if (IsA(subplan, ModifyTable))
- subplanstate = NULL;
- else
- subplanstate = ExecInitNode(subplan, estate, 0);
-
+ subplanstate = ExecInitNode(subplan, estate, 0);
estate->es_subplanstates = lappend(estate->es_subplanstates,
subplanstate);
}