diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-26 02:26:45 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-26 02:26:45 +0000 |
commit | 9f2ee8f287098fb8067593b38da0650df458b20a (patch) | |
tree | 8998549ba80c6f5b397ad1e77dc6f03aefee00c2 /src/backend/nodes | |
parent | 76d8883c8e3647ac2f7ff3c48226a25b1fd7888b (diff) | |
download | postgresql-9f2ee8f287098fb8067593b38da0650df458b20a.tar.gz postgresql-9f2ee8f287098fb8067593b38da0650df458b20a.zip |
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/nodes')
-rw-r--r-- | src/backend/nodes/copyfuncs.c | 31 | ||||
-rw-r--r-- | src/backend/nodes/equalfuncs.c | 5 | ||||
-rw-r--r-- | src/backend/nodes/outfuncs.c | 28 | ||||
-rw-r--r-- | src/backend/nodes/readfuncs.c | 5 |
4 files changed, 52 insertions, 17 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 92da5324c24..deee9994170 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.448 2009/10/14 22:14:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.449 2009/10/26 02:26:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -174,6 +174,8 @@ _copyModifyTable(ModifyTable *from) COPY_NODE_FIELD(resultRelations); COPY_NODE_FIELD(plans); COPY_NODE_FIELD(returningLists); + COPY_NODE_FIELD(rowMarks); + COPY_SCALAR_FIELD(epqParam); return newnode; } @@ -812,6 +814,7 @@ _copyLockRows(LockRows *from) * copy remainder of node */ COPY_NODE_FIELD(rowMarks); + COPY_SCALAR_FIELD(epqParam); return newnode; } @@ -839,6 +842,26 @@ _copyLimit(Limit *from) } /* + * _copyPlanRowMark + */ +static PlanRowMark * +_copyPlanRowMark(PlanRowMark *from) +{ + PlanRowMark *newnode = makeNode(PlanRowMark); + + COPY_SCALAR_FIELD(rti); + COPY_SCALAR_FIELD(prti); + COPY_SCALAR_FIELD(markType); + COPY_SCALAR_FIELD(noWait); + COPY_SCALAR_FIELD(isParent); + COPY_SCALAR_FIELD(ctidAttNo); + COPY_SCALAR_FIELD(toidAttNo); + COPY_SCALAR_FIELD(wholeAttNo); + + return newnode; +} + +/* * _copyPlanInvalItem */ static PlanInvalItem * @@ -1834,11 +1857,8 @@ _copyRowMarkClause(RowMarkClause *from) RowMarkClause *newnode = makeNode(RowMarkClause); COPY_SCALAR_FIELD(rti); - COPY_SCALAR_FIELD(prti); - COPY_SCALAR_FIELD(rowmarkId); COPY_SCALAR_FIELD(forUpdate); COPY_SCALAR_FIELD(noWait); - COPY_SCALAR_FIELD(isParent); return newnode; } @@ -3621,6 +3641,9 @@ copyObject(void *from) case T_Limit: retval = _copyLimit(from); break; + case T_PlanRowMark: + retval = _copyPlanRowMark(from); + break; case T_PlanInvalItem: retval = _copyPlanInvalItem(from); break; diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 0c30d6aa9d7..f7e9547a1f8 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -22,7 +22,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.370 2009/10/14 22:14:21 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.371 2009/10/26 02:26:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2196,11 +2196,8 @@ static bool _equalRowMarkClause(RowMarkClause *a, RowMarkClause *b) { COMPARE_SCALAR_FIELD(rti); - COMPARE_SCALAR_FIELD(prti); - COMPARE_SCALAR_FIELD(rowmarkId); COMPARE_SCALAR_FIELD(forUpdate); COMPARE_SCALAR_FIELD(noWait); - COMPARE_SCALAR_FIELD(isParent); return true; } diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 45caaea850a..ae7a859bd55 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.369 2009/10/13 00:53:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.370 2009/10/26 02:26:31 tgl Exp $ * * NOTES * Every node type that can appear in stored rules' parsetrees *must* @@ -329,6 +329,8 @@ _outModifyTable(StringInfo str, ModifyTable *node) WRITE_NODE_FIELD(resultRelations); WRITE_NODE_FIELD(plans); WRITE_NODE_FIELD(returningLists); + WRITE_NODE_FIELD(rowMarks); + WRITE_INT_FIELD(epqParam); } static void @@ -729,6 +731,7 @@ _outLockRows(StringInfo str, LockRows *node) _outPlanInfo(str, (Plan *) node); WRITE_NODE_FIELD(rowMarks); + WRITE_INT_FIELD(epqParam); } static void @@ -743,6 +746,21 @@ _outLimit(StringInfo str, Limit *node) } static void +_outPlanRowMark(StringInfo str, PlanRowMark *node) +{ + WRITE_NODE_TYPE("PLANROWMARK"); + + WRITE_UINT_FIELD(rti); + WRITE_UINT_FIELD(prti); + WRITE_ENUM_FIELD(markType, RowMarkType); + WRITE_BOOL_FIELD(noWait); + WRITE_BOOL_FIELD(isParent); + WRITE_INT_FIELD(ctidAttNo); + WRITE_INT_FIELD(toidAttNo); + WRITE_INT_FIELD(wholeAttNo); +} + +static void _outPlanInvalItem(StringInfo str, PlanInvalItem *node) { WRITE_NODE_TYPE("PLANINVALITEM"); @@ -1512,7 +1530,6 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node) WRITE_NODE_FIELD(relationOids); WRITE_NODE_FIELD(invalItems); WRITE_UINT_FIELD(lastPHId); - WRITE_UINT_FIELD(lastRowmarkId); WRITE_BOOL_FIELD(transientPlan); } @@ -1536,6 +1553,7 @@ _outPlannerInfo(StringInfo str, PlannerInfo *node) WRITE_NODE_FIELD(full_join_clauses); WRITE_NODE_FIELD(join_info_list); WRITE_NODE_FIELD(append_rel_list); + WRITE_NODE_FIELD(rowMarks); WRITE_NODE_FIELD(placeholder_list); WRITE_NODE_FIELD(query_pathkeys); WRITE_NODE_FIELD(group_pathkeys); @@ -2016,11 +2034,8 @@ _outRowMarkClause(StringInfo str, RowMarkClause *node) WRITE_NODE_TYPE("ROWMARKCLAUSE"); WRITE_UINT_FIELD(rti); - WRITE_UINT_FIELD(prti); - WRITE_UINT_FIELD(rowmarkId); WRITE_BOOL_FIELD(forUpdate); WRITE_BOOL_FIELD(noWait); - WRITE_BOOL_FIELD(isParent); } static void @@ -2526,6 +2541,9 @@ _outNode(StringInfo str, void *obj) case T_Limit: _outLimit(str, obj); break; + case T_PlanRowMark: + _outPlanRowMark(str, obj); + break; case T_PlanInvalItem: _outPlanInvalItem(str, obj); break; diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 7cffedb73b4..a1520276e22 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.225 2009/10/12 18:10:45 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.226 2009/10/26 02:26:32 tgl Exp $ * * NOTES * Path and Plan nodes do not have any readfuncs support, because we @@ -293,11 +293,8 @@ _readRowMarkClause(void) READ_LOCALS(RowMarkClause); READ_UINT_FIELD(rti); - READ_UINT_FIELD(prti); - READ_UINT_FIELD(rowmarkId); READ_BOOL_FIELD(forUpdate); READ_BOOL_FIELD(noWait); - READ_BOOL_FIELD(isParent); READ_DONE(); } |