aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeBitmapHeapscan.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/executor/nodeBitmapHeapscan.c
parent76d8883c8e3647ac2f7ff3c48226a25b1fd7888b (diff)
downloadpostgresql-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/nodeBitmapHeapscan.c')
-rw-r--r--src/backend/executor/nodeBitmapHeapscan.c80
1 files changed, 27 insertions, 53 deletions
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 6adc7d66ee9..98d9219e478 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -21,7 +21,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.36 2009/09/27 21:10:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.37 2009/10/26 02:26:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -60,10 +60,8 @@ static void bitgetpage(HeapScanDesc scan, TBMIterateResult *tbmres);
static TupleTableSlot *
BitmapHeapNext(BitmapHeapScanState *node)
{
- EState *estate;
ExprContext *econtext;
HeapScanDesc scan;
- Index scanrelid;
TIDBitmap *tbm;
TBMIterator *tbmiterator;
TBMIterateResult *tbmres;
@@ -74,46 +72,15 @@ BitmapHeapNext(BitmapHeapScanState *node)
/*
* extract necessary information from index scan node
*/
- estate = node->ss.ps.state;
econtext = node->ss.ps.ps_ExprContext;
slot = node->ss.ss_ScanTupleSlot;
scan = node->ss.ss_currentScanDesc;
- scanrelid = ((BitmapHeapScan *) node->ss.ps.plan)->scan.scanrelid;
tbm = node->tbm;
tbmiterator = node->tbmiterator;
tbmres = node->tbmres;
prefetch_iterator = node->prefetch_iterator;
/*
- * 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 IndexScan --> 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);
-
- ExecStoreTuple(estate->es_evTuple[scanrelid - 1],
- slot, InvalidBuffer, false);
-
- /* Does the tuple meet the original qual conditions? */
- econtext->ecxt_scantuple = slot;
-
- ResetExprContext(econtext);
-
- if (!ExecQual(node->bitmapqualorig, econtext, false))
- ExecClearTuple(slot); /* would not be returned by scan */
-
- /* Flag for the next call that no more tuples */
- estate->es_evTupleNull[scanrelid - 1] = true;
-
- return slot;
- }
-
- /*
* If we haven't yet performed the underlying index scan, do it, and begin
* the iteration over the bitmap.
*
@@ -419,6 +386,27 @@ bitgetpage(HeapScanDesc scan, TBMIterateResult *tbmres)
scan->rs_ntuples = ntup;
}
+/*
+ * BitmapHeapRecheck -- access method routine to recheck a tuple in EvalPlanQual
+ */
+static bool
+BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot)
+{
+ ExprContext *econtext;
+
+ /*
+ * extract necessary information from index scan node
+ */
+ econtext = node->ss.ps.ps_ExprContext;
+
+ /* Does the tuple meet the original qual conditions? */
+ econtext->ecxt_scantuple = slot;
+
+ ResetExprContext(econtext);
+
+ return ExecQual(node->bitmapqualorig, econtext, false);
+}
+
/* ----------------------------------------------------------------
* ExecBitmapHeapScan(node)
* ----------------------------------------------------------------
@@ -426,10 +414,9 @@ bitgetpage(HeapScanDesc scan, TBMIterateResult *tbmres)
TupleTableSlot *
ExecBitmapHeapScan(BitmapHeapScanState *node)
{
- /*
- * use BitmapHeapNext as access method
- */
- return ExecScan(&node->ss, (ExecScanAccessMtd) BitmapHeapNext);
+ return ExecScan(&node->ss,
+ (ExecScanAccessMtd) BitmapHeapNext,
+ (ExecScanRecheckMtd) BitmapHeapRecheck);
}
/* ----------------------------------------------------------------
@@ -439,14 +426,6 @@ ExecBitmapHeapScan(BitmapHeapScanState *node)
void
ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt)
{
- EState *estate;
- Index scanrelid;
-
- estate = node->ss.ps.state;
- scanrelid = ((BitmapHeapScan *) node->ss.ps.plan)->scan.scanrelid;
-
- node->ss.ps.ps_TupFromTlist = false;
-
/*
* If we are being passed an outer tuple, link it into the "regular"
* per-tuple econtext for possible qual eval.
@@ -459,13 +438,6 @@ ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt)
stdecontext->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;
- }
-
/* rescan to release any page pin */
heap_rescan(node->ss.ss_currentScanDesc, NULL);
@@ -480,6 +452,8 @@ ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt)
node->tbmres = NULL;
node->prefetch_iterator = NULL;
+ ExecScanReScan(&node->ss);
+
/*
* Always rescan the input immediately, to ensure we can pass down any
* outer tuple that might be used in index quals.