OSDN Git Service

Fix improper matching of resjunk column names for FOR UPDATE in subselect.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 10 Feb 2011 04:27:16 +0000 (23:27 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 10 Feb 2011 04:27:16 +0000 (23:27 -0500)
commitd5478c3391f8f1a243abbc3d9253aac3d6d3538e
tree2ba9720f22ab22f87b56853a012728bd17146992
parent5dfc66b3d0b96f3a75adc4cd9c9f6d15c061cabd
Fix improper matching of resjunk column names for FOR UPDATE in subselect.

Flattening of subquery range tables during setrefs.c could lead to the
rangetable indexes in PlanRowMark nodes not matching up with the column
names previously assigned to the corresponding resjunk ctid (resp. tableoid
or wholerow) columns.  Typical symptom would be either a "cannot extract
system attribute from virtual tuple" error or an Assert failure.  This
wasn't a problem before 9.0 because we didn't support FOR UPDATE below the
top query level, and so the final flattening could never renumber an RTE
that was relevant to FOR UPDATE.  Fix by using a plan-tree-wide unique
number for each PlanRowMark to label the associated resjunk columns, so
that the number need not change during flattening.

Per report from David Johnston (though I'm darned if I can see how this got
past initial testing of the relevant code).  Back-patch to 9.0.
src/backend/executor/execMain.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/outfuncs.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/setrefs.c
src/backend/optimizer/prep/preptlist.c
src/backend/optimizer/prep/prepunion.c
src/include/nodes/execnodes.h
src/include/nodes/plannodes.h
src/include/nodes/relation.h