提交 86c6538d 编写于 作者: T Tom Lane

Fix a couple of places in execMain that erroneously assumed that SELECT FOR

UPDATE/SHARE couldn't occur as a subquery in a query with a non-SELECT
top-level operation.  Symptoms included outright failure (as in report from
Mark Mielke) and silently neglecting to take the requested row locks.

Back-patch to 8.3, because the visible failure in the INSERT ... SELECT case
is a regression from 8.2.  I'm a bit hesitant to back-patch further given the
lack of field complaints.
上级 254d66e2
......@@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.303 2008/02/07 17:09:51 tgl Exp $
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.303.2.1 2008/04/21 03:49:51 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -758,6 +758,16 @@ InitPlan(QueryDesc *queryDesc, int eflags)
*/
estate->es_junkFilter =
estate->es_result_relation_info->ri_junkFilter;
/*
* We currently can't support rowmarks in this case, because
* the associated junk CTIDs might have different resnos in
* different subplans.
*/
if (estate->es_rowMarks)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE is not supported within a query with multiple result relations")));
}
else
{
......@@ -775,18 +785,6 @@ InitPlan(QueryDesc *queryDesc, int eflags)
{
/* For SELECT, want to return the cleaned tuple type */
tupType = j->jf_cleanTupType;
/* For SELECT FOR UPDATE/SHARE, find the ctid attrs now */
foreach(l, estate->es_rowMarks)
{
ExecRowMark *erm = (ExecRowMark *) lfirst(l);
char resname[32];
snprintf(resname, sizeof(resname), "ctid%u", erm->rti);
erm->ctidAttNo = ExecFindJunkAttribute(j, resname);
if (!AttributeNumberIsValid(erm->ctidAttNo))
elog(ERROR, "could not find junk \"%s\" column",
resname);
}
}
else if (operation == CMD_UPDATE || operation == CMD_DELETE)
{
......@@ -795,10 +793,27 @@ InitPlan(QueryDesc *queryDesc, int eflags)
if (!AttributeNumberIsValid(j->jf_junkAttNo))
elog(ERROR, "could not find junk ctid column");
}
/* For SELECT FOR UPDATE/SHARE, find the ctid attrs now */
foreach(l, estate->es_rowMarks)
{
ExecRowMark *erm = (ExecRowMark *) lfirst(l);
char resname[32];
snprintf(resname, sizeof(resname), "ctid%u", erm->rti);
erm->ctidAttNo = ExecFindJunkAttribute(j, resname);
if (!AttributeNumberIsValid(erm->ctidAttNo))
elog(ERROR, "could not find junk \"%s\" column",
resname);
}
}
}
else
{
estate->es_junkFilter = NULL;
if (estate->es_rowMarks)
elog(ERROR, "SELECT FOR UPDATE/SHARE, but no junk columns");
}
}
/*
......@@ -1244,40 +1259,21 @@ lnext: ;
slot = planSlot;
/*
* if we have a junk filter, then project a new tuple with the junk
* If we have a junk filter, then project a new tuple with the junk
* removed.
*
* Store this new "clean" tuple in the junkfilter's resultSlot.
* (Formerly, we stored it back over the "dirty" tuple, which is WRONG
* because that tuple slot has the wrong descriptor.)
*
* Also, extract all the junk information we need.
* But first, extract all the junk information we need.
*/
if ((junkfilter = estate->es_junkFilter) != NULL)
{
Datum datum;
bool isNull;
/*
* extract the 'ctid' junk attribute.
*/
if (operation == CMD_UPDATE || operation == CMD_DELETE)
{
datum = ExecGetJunkAttribute(slot, junkfilter->jf_junkAttNo,
&isNull);
/* shouldn't ever get a null result... */
if (isNull)
elog(ERROR, "ctid is NULL");
tupleid = (ItemPointer) DatumGetPointer(datum);
tuple_ctid = *tupleid; /* make sure we don't free the ctid!! */
tupleid = &tuple_ctid;
}
/*
* Process any FOR UPDATE or FOR SHARE locking requested.
*/
else if (estate->es_rowMarks != NIL)
if (estate->es_rowMarks != NIL)
{
ListCell *l;
......@@ -1285,6 +1281,8 @@ lnext: ;
foreach(l, estate->es_rowMarks)
{
ExecRowMark *erm = lfirst(l);
Datum datum;
bool isNull;
HeapTupleData tuple;
Buffer buffer;
ItemPointerData update_ctid;
......@@ -1356,6 +1354,25 @@ lnext: ;
}
}
/*
* extract the 'ctid' junk attribute.
*/
if (operation == CMD_UPDATE || operation == CMD_DELETE)
{
Datum datum;
bool isNull;
datum = ExecGetJunkAttribute(slot, junkfilter->jf_junkAttNo,
&isNull);
/* shouldn't ever get a null result... */
if (isNull)
elog(ERROR, "ctid is NULL");
tupleid = (ItemPointer) DatumGetPointer(datum);
tuple_ctid = *tupleid; /* make sure we don't free the ctid!! */
tupleid = &tuple_ctid;
}
/*
* Create a new "clean" tuple with all junk attributes removed. We
* don't need to do this for DELETE, however (there will in fact
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册