diff options
author | Tom Lane | 2009-10-26 02:26:45 +0000 |
---|---|---|
committer | Tom Lane | 2009-10-26 02:26:45 +0000 |
commit | 9f2ee8f287098fb8067593b38da0650df458b20a (patch) | |
tree | 8998549ba80c6f5b397ad1e77dc6f03aefee00c2 /src/backend/executor/nodeTidscan.c | |
parent | 76d8883c8e3647ac2f7ff3c48226a25b1fd7888b (diff) |
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/executor/nodeTidscan.c')
-rw-r--r-- | src/backend/executor/nodeTidscan.c | 74 |
1 files changed, 23 insertions, 51 deletions
diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c index 1fc74695eec..7e4a5c7a077 100644 --- a/src/backend/executor/nodeTidscan.c +++ b/src/backend/executor/nodeTidscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.63 2009/09/27 21:10:53 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeTidscan.c,v 1.64 2009/10/26 02:26:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -258,7 +258,6 @@ TidNext(TidScanState *node) Relation heapRelation; HeapTuple tuple; TupleTableSlot *slot; - Index scanrelid; Buffer buffer = InvalidBuffer; ItemPointerData *tidList; int numTids; @@ -272,33 +271,6 @@ TidNext(TidScanState *node) snapshot = estate->es_snapshot; heapRelation = node->ss.ss_currentRelation; slot = node->ss.ss_ScanTupleSlot; - scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid; - - /* - * Check if we are evaluating PlanQual for tuple of this relation. - * Additional checking is not good, but no other way for now. We could - * introduce new nodes for this case and handle TidScan --> NewNode - * switching in Init/ReScan plan... - */ - if (estate->es_evTuple != NULL && - estate->es_evTuple[scanrelid - 1] != NULL) - { - if (estate->es_evTupleNull[scanrelid - 1]) - return ExecClearTuple(slot); - - /* - * XXX shouldn't we check here to make sure tuple matches TID list? In - * runtime-key case this is not certain, is it? However, in the WHERE - * CURRENT OF case it might not match anyway ... - */ - - ExecStoreTuple(estate->es_evTuple[scanrelid - 1], - slot, InvalidBuffer, false); - - /* Flag for the next call that no more tuples */ - estate->es_evTupleNull[scanrelid - 1] = true; - return slot; - } /* * First time through, compute the list of TIDs to be visited @@ -384,13 +356,28 @@ TidNext(TidScanState *node) return ExecClearTuple(slot); } +/* + * TidRecheck -- access method routine to recheck a tuple in EvalPlanQual + */ +static bool +TidRecheck(TidScanState *node, TupleTableSlot *slot) +{ + /* + * XXX shouldn't we check here to make sure tuple matches TID list? In + * runtime-key case this is not certain, is it? However, in the WHERE + * CURRENT OF case it might not match anyway ... + */ + return true; +} + + /* ---------------------------------------------------------------- * ExecTidScan(node) * * Scans the relation using tids and returns * the next qualifying tuple in the direction specified. - * It calls ExecScan() and passes it the access methods which returns - * the next tuple using the tids. + * We call the ExecScan() routine and pass it the appropriate + * access method functions. * * Conditions: * -- the "cursor" maintained by the AMI is positioned at the tuple @@ -405,10 +392,9 @@ TidNext(TidScanState *node) TupleTableSlot * ExecTidScan(TidScanState *node) { - /* - * use TidNext as access method - */ - return ExecScan(&node->ss, (ExecScanAccessMtd) TidNext); + return ExecScan(&node->ss, + (ExecScanAccessMtd) TidNext, + (ExecScanRecheckMtd) TidRecheck); } /* ---------------------------------------------------------------- @@ -418,32 +404,18 @@ ExecTidScan(TidScanState *node) void ExecTidReScan(TidScanState *node, ExprContext *exprCtxt) { - EState *estate; - Index scanrelid; - - estate = node->ss.ps.state; - scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid; - - node->ss.ps.ps_TupFromTlist = false; - /* If we are being passed an outer tuple, save it for runtime key calc */ if (exprCtxt != NULL) node->ss.ps.ps_ExprContext->ecxt_outertuple = exprCtxt->ecxt_outertuple; - /* If this is re-scanning of PlanQual ... */ - if (estate->es_evTuple != NULL && - estate->es_evTuple[scanrelid - 1] != NULL) - { - estate->es_evTupleNull[scanrelid - 1] = false; - return; - } - if (node->tss_TidList) pfree(node->tss_TidList); node->tss_TidList = NULL; node->tss_NumTids = 0; node->tss_TidPtr = -1; + + ExecScanReScan(&node->ss); } /* ---------------------------------------------------------------- |