summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/prepunion.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-10-26 02:26:45 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-10-26 02:26:45 +0000
commit9f2ee8f287098fb8067593b38da0650df458b20a (patch)
tree8998549ba80c6f5b397ad1e77dc6f03aefee00c2 /src/backend/optimizer/prep/prepunion.c
parent76d8883c8e3647ac2f7ff3c48226a25b1fd7888b (diff)
downloadpostgresql-9f2ee8f287098fb8067593b38da0650df458b20a.tar.gz
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the "current" row for every joined relation in UPDATE, DELETE, and SELECT FOR UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the appropriate row into each scan node in the rechecking plan, forcing it to emit only that one row. The former behavior could rescan the whole of each joined relation for each recheck, which was terrible for performance, and what's much worse could result in duplicated output tuples. Also, the original implementation of EvalPlanQual could not re-use the recheck execution tree --- it had to go through a full executor init and shutdown for every row to be tested. To avoid this overhead, I've associated a special runtime Param with each LockRows or ModifyTable plan node, and arranged to make every scan node below such a node depend on that Param. Thus, by signaling a change in that Param, the EPQ machinery can just rescan the already-built test plan. This patch also adds a prohibition on set-returning functions in the targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the duplicate-output-tuple problem. It seems fairly reasonable since the other restrictions on SELECT FOR UPDATE are meant to ensure that there is a unique correspondence between source tuples and result tuples, which an output SRF destroys as much as anything else does.
Diffstat (limited to 'src/backend/optimizer/prep/prepunion.c')
-rw-r--r--src/backend/optimizer/prep/prepunion.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index e4fe0db547..93a3e25b17 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -22,7 +22,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.177 2009/10/23 05:24:52 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.178 2009/10/26 02:26:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -248,7 +248,7 @@ recurse_set_operations(Node *setOp, PlannerInfo *root,
rtr->rtindex,
subplan,
subroot->parse->rtable,
- subroot->parse->rowMarks);
+ subroot->rowMarks);
/*
* We don't bother to determine the subquery's output ordering since
@@ -1133,7 +1133,7 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
{
Query *parse = root->parse;
Oid parentOID;
- RowMarkClause *oldrc;
+ PlanRowMark *oldrc;
Relation oldrelation;
LOCKMODE lockmode;
List *inhOIDs;
@@ -1171,10 +1171,10 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
* the lock, leading to possible deadlocks. (This code should match the
* parser and rewriter.)
*/
- oldrc = get_rowmark(parse, rti);
+ oldrc = get_plan_rowmark(root->rowMarks, rti);
if (rti == parse->resultRelation)
lockmode = RowExclusiveLock;
- else if (oldrc)
+ else if (oldrc && RowMarkRequiresRowShareLock(oldrc->markType))
lockmode = RowShareLock;
else
lockmode = AccessShareLock;
@@ -1196,7 +1196,7 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
/*
* If parent relation is selected FOR UPDATE/SHARE, we need to mark its
- * RowMarkClause as isParent = true, and generate a new RowMarkClause for
+ * PlanRowMark as isParent = true, and generate a new PlanRowMark for
* each child.
*/
if (oldrc)
@@ -1275,21 +1275,23 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
}
/*
- * Build a RowMarkClause if parent is marked FOR UPDATE/SHARE.
+ * Build a PlanRowMark if parent is marked FOR UPDATE/SHARE.
*/
if (oldrc)
{
- RowMarkClause *newrc = makeNode(RowMarkClause);
+ PlanRowMark *newrc = makeNode(PlanRowMark);
newrc->rti = childRTindex;
newrc->prti = rti;
- /* children use the same rowmarkId as their parent */
- newrc->rowmarkId = oldrc->rowmarkId;
- newrc->forUpdate = oldrc->forUpdate;
+ newrc->markType = oldrc->markType;
newrc->noWait = oldrc->noWait;
newrc->isParent = false;
+ /* junk attrs for children are not identified yet */
+ newrc->ctidAttNo = InvalidAttrNumber;
+ newrc->toidAttNo = InvalidAttrNumber;
+ newrc->wholeAttNo = InvalidAttrNumber;
- parse->rowMarks = lappend(parse->rowMarks, newrc);
+ root->rowMarks = lappend(root->rowMarks, newrc);
}
/* Close child relations, but keep locks */