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/executor/nodeSubqueryscan.c | |
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/executor/nodeSubqueryscan.c')
-rw-r--r-- | src/backend/executor/nodeSubqueryscan.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/backend/executor/nodeSubqueryscan.c b/src/backend/executor/nodeSubqueryscan.c index 15929dedffe..402c24e6285 100644 --- a/src/backend/executor/nodeSubqueryscan.c +++ b/src/backend/executor/nodeSubqueryscan.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.42 2009/10/12 18:10:43 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.43 2009/10/26 02:26:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -48,41 +48,43 @@ SubqueryNext(SubqueryScanState *node) TupleTableSlot *slot; /* - * We need not support EvalPlanQual here, since we are not scanning a real - * relation. - */ - - /* * Get the next tuple from the sub-query. */ slot = ExecProcNode(node->subplan); /* - * We just overwrite our ScanTupleSlot with the subplan's result slot, - * rather than expending the cycles for ExecCopySlot(). + * We just return the subplan's result slot, rather than expending + * extra cycles for ExecCopySlot(). (Our own ScanTupleSlot is used + * only for EvalPlanQual rechecks.) */ - node->ss.ss_ScanTupleSlot = slot; - return slot; } +/* + * SubqueryRecheck -- access method routine to recheck a tuple in EvalPlanQual + */ +static bool +SubqueryRecheck(SubqueryScanState *node, TupleTableSlot *slot) +{ + /* nothing to check */ + return true; +} + /* ---------------------------------------------------------------- * ExecSubqueryScan(node) * * Scans the subquery sequentially and returns the next qualifying * tuple. - * It calls the ExecScan() routine and passes it the access method - * which retrieve tuples sequentially. - * + * We call the ExecScan() routine and pass it the appropriate + * access method functions. + * ---------------------------------------------------------------- */ - TupleTableSlot * ExecSubqueryScan(SubqueryScanState *node) { - /* - * use SubqueryNext as access method - */ - return ExecScan(&node->ss, (ExecScanAccessMtd) SubqueryNext); + return ExecScan(&node->ss, + (ExecScanAccessMtd) SubqueryNext, + (ExecScanRecheckMtd) SubqueryRecheck); } /* ---------------------------------------------------------------- @@ -176,7 +178,7 @@ ExecEndSubqueryScan(SubqueryScanState *node) * clean out the upper tuple table */ ExecClearTuple(node->ss.ps.ps_ResultTupleSlot); - node->ss.ss_ScanTupleSlot = NULL; /* not ours to clear */ + ExecClearTuple(node->ss.ss_ScanTupleSlot); /* * close down subquery @@ -193,9 +195,7 @@ ExecEndSubqueryScan(SubqueryScanState *node) void ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt) { - EState *estate; - - estate = node->ss.ps.state; + ExecScanReScan(&node->ss); /* * ExecReScan doesn't know about my subplan, so I have to do @@ -211,7 +211,4 @@ ExecSubqueryReScan(SubqueryScanState *node, ExprContext *exprCtxt) */ if (node->subplan->chgParam == NULL) ExecReScan(node->subplan, NULL); - - node->ss.ss_ScanTupleSlot = NULL; - node->ss.ps.ps_TupFromTlist = false; } |