postgresql/src/include/optimizer
Tom Lane 9fa82c9809 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.
2012-04-25 20:20:33 -04:00
..
clauses.h Allow LEAKPROOF functions for better performance of security views. 2012-02-13 22:21:14 -05:00
cost.h Revise parameterized-path mechanism to fix assorted issues. 2012-04-19 15:53:47 -04:00
geqo_copy.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo_gene.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo_misc.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo_mutation.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo_pool.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo_random.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo_recombination.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo_selection.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
geqo.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
joininfo.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
pathnode.h Revise parameterized-path mechanism to fix assorted issues. 2012-04-19 15:53:47 -04:00
paths.h Revise parameterized-path mechanism to fix assorted issues. 2012-04-19 15:53:47 -04:00
placeholder.h Revisit handling of UNION ALL subqueries with non-Var output columns. 2012-03-16 13:11:55 -04:00
plancat.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
planmain.h Fix planner's handling of RETURNING lists in writable CTEs. 2012-04-25 20:20:33 -04:00
planner.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
predtest.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
prep.h Preserve column names in the execution-time tupledesc for a RowExpr. 2012-02-14 17:34:56 -05:00
restrictinfo.h Revise parameterized-path mechanism to fix assorted issues. 2012-04-19 15:53:47 -04:00
subselect.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
tlist.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
var.h Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00