aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/createplan.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-04-25 20:20:33 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-04-25 20:20:33 -0400
commit9fa82c980935ef4aee18fabe8da20ae2198b052a (patch)
treec8345ab2665cc49129875f9921d6f6de1b097834 /src/backend/optimizer/plan/createplan.c
parentc62b8eaae11aaa69a2b71bc63f9f78ca72eb412c (diff)
downloadpostgresql-9fa82c980935ef4aee18fabe8da20ae2198b052a.tar.gz
postgresql-9fa82c980935ef4aee18fabe8da20ae2198b052a.zip
Fix planner's handling of RETURNING lists in writable CTEs.
setrefs.c failed to do "rtoffset" adjustment of Vars in RETURNING lists, which meant they were left with the wrong varnos when the RETURNING list was in a subquery. That was never possible before writable CTEs, of course, but now it's broken. The executor fails to notice any problem because ExecEvalVar just references the ecxt_scantuple for any normal varno; but EXPLAIN breaks when the varno is wrong, as illustrated in a recent complaint from Bartosz Dmytrak. Since the eventual rtoffset of the subquery is not known at the time we are preparing its plan node, the previous scheme of executing set_returning_clause_references() at that time cannot handle this adjustment. Fortunately, it turns out that we don't really need to do it that way, because all the needed information is available during normal setrefs.c execution; we just have to dig it out of the ModifyTable node. So, do that, and get rid of the kluge of early setrefs processing of RETURNING lists. (This is a little bit of a cheat in the case of inherited UPDATE/DELETE, because we are not passing a "root" struct that corresponds exactly to what the subplan was built with. But that doesn't matter, and anyway this is less ugly than early setrefs processing was.) Back-patch to 9.1, where the problem became possible to hit.
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r--src/backend/optimizer/plan/createplan.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index de2779a1a25..c34b9b8c38e 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -4587,16 +4587,8 @@ make_modifytable(CmdType operation, bool canSetTag,
node->plan.lefttree = NULL;
node->plan.righttree = NULL;
node->plan.qual = NIL;
-
- /*
- * Set up the visible plan targetlist as being the same as the first
- * RETURNING list. This is for the use of EXPLAIN; the executor won't pay
- * any attention to the targetlist.
- */
- if (returningLists)
- node->plan.targetlist = copyObject(linitial(returningLists));
- else
- node->plan.targetlist = NIL;
+ /* setrefs.c will fill in the targetlist, if needed */
+ node->plan.targetlist = NIL;
node->operation = operation;
node->canSetTag = canSetTag;