aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeModifyTable.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-02-25 23:53:34 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-02-25 23:53:34 -0500
commit000128bc7f591025d0c1ce539bb53c6ad00ab69c (patch)
tree8fc01820c448c8ad7ebfe0bd836ff97be74f3f44 /src/backend/executor/nodeModifyTable.c
parent389af951552ff2209eae3e62fa147fef12329d4f (diff)
downloadpostgresql-000128bc7f591025d0c1ce539bb53c6ad00ab69c.tar.gz
postgresql-000128bc7f591025d0c1ce539bb53c6ad00ab69c.zip
Fix order of shutdown processing when CTEs contain inter-references.
We need ExecutorEnd to run the ModifyTable nodes to completion in reverse order of initialization, not forward order. Easily done by constructing the list back-to-front.
Diffstat (limited to 'src/backend/executor/nodeModifyTable.c')
-rw-r--r--src/backend/executor/nodeModifyTable.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index cf32dc56903..f10f70a17d3 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1147,11 +1147,14 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
* Lastly, if this is not the primary (canSetTag) ModifyTable node, add it
* to estate->es_auxmodifytables so that it will be run to completion by
* ExecPostprocessPlan. (It'd actually work fine to add the primary
- * ModifyTable node too, but there's no need.)
+ * ModifyTable node too, but there's no need.) Note the use of lcons
+ * not lappend: we need later-initialized ModifyTable nodes to be shut
+ * down before earlier ones. This ensures that we don't throw away
+ * RETURNING rows that need to be seen by a later CTE subplan.
*/
if (!mtstate->canSetTag)
- estate->es_auxmodifytables = lappend(estate->es_auxmodifytables,
- mtstate);
+ estate->es_auxmodifytables = lcons(mtstate,
+ estate->es_auxmodifytables);
return mtstate;
}