aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-02-09 23:27:07 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-02-09 23:27:42 -0500
commite617f0d7e4084f85104361568ef5f865ebfa0005 (patch)
tree396531b6333cbb242b8d9259e70f6e45df3a1364 /src/backend/executor/execMain.c
parent5478f991c9f73066d27d75b31876f9977af61db5 (diff)
downloadpostgresql-e617f0d7e4084f85104361568ef5f865ebfa0005.tar.gz
postgresql-e617f0d7e4084f85104361568ef5f865ebfa0005.zip
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.
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r--src/backend/executor/execMain.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 600f7e03345..7df7f5cdf0d 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -742,6 +742,7 @@ InitPlan(QueryDesc *queryDesc, int eflags)
erm->relation = relation;
erm->rti = rc->rti;
erm->prti = rc->prti;
+ erm->rowmarkId = rc->rowmarkId;
erm->markType = rc->markType;
erm->noWait = rc->noWait;
ItemPointerSetInvalid(&(erm->curCtid));
@@ -1425,23 +1426,29 @@ ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist)
/* if child rel, need tableoid */
if (erm->rti != erm->prti)
{
- snprintf(resname, sizeof(resname), "tableoid%u", erm->prti);
+ snprintf(resname, sizeof(resname), "tableoid%u", erm->rowmarkId);
aerm->toidAttNo = ExecFindJunkAttributeInTlist(targetlist,
resname);
+ if (!AttributeNumberIsValid(aerm->toidAttNo))
+ elog(ERROR, "could not find junk %s column", resname);
}
/* always need ctid for real relations */
- snprintf(resname, sizeof(resname), "ctid%u", erm->prti);
+ snprintf(resname, sizeof(resname), "ctid%u", erm->rowmarkId);
aerm->ctidAttNo = ExecFindJunkAttributeInTlist(targetlist,
resname);
+ if (!AttributeNumberIsValid(aerm->ctidAttNo))
+ elog(ERROR, "could not find junk %s column", resname);
}
else
{
Assert(erm->markType == ROW_MARK_COPY);
- snprintf(resname, sizeof(resname), "wholerow%u", erm->prti);
+ snprintf(resname, sizeof(resname), "wholerow%u", erm->rowmarkId);
aerm->wholeAttNo = ExecFindJunkAttributeInTlist(targetlist,
resname);
+ if (!AttributeNumberIsValid(aerm->wholeAttNo))
+ elog(ERROR, "could not find junk %s column", resname);
}
return aerm;