*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.7 2005/04/25 01:30:12 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.8 2005/05/05 03:37:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
#define MAX_TIDS 1024
TIDBitmap *tbm;
- Oid indexid;
- Relation indexRelation;
IndexScanDesc scandesc;
ItemPointerData tids[MAX_TIDS];
int32 ntids;
if (node->ss.ps.instrument)
InstrStartNode(node->ss.ps.instrument);
+ /*
+ * extract necessary information from index scan node
+ */
+ scandesc = node->biss_ScanDesc;
+
/*
* If we have runtime keys and they've not already been set up, do it
* now.
if (node->biss_RuntimeKeyInfo && !node->biss_RuntimeKeysReady)
ExecReScan((PlanState *) node, NULL);
- /*
- * We do not open or lock the base relation here. We assume that an
- * ancestor BitmapHeapScan node is holding AccessShareLock on the
- * heap relation throughout the execution of the plan tree.
- */
-
- /*
- * open the index relation and initialize relation and scan
- * descriptors. Note we acquire no locks here; the index machinery
- * does its own locks and unlocks.
- */
- indexid = ((BitmapIndexScan *) node->ss.ps.plan)->indexid;
- indexRelation = index_open(indexid);
- scandesc = index_beginscan_multi(indexRelation,
- node->ss.ps.state->es_snapshot,
- node->biss_NumScanKeys,
- node->biss_ScanKeys);
-
/*
* Prepare the result bitmap. Normally we just create a new one to pass
* back; however, our parent node is allowed to store a pre-made one
CHECK_FOR_INTERRUPTS();
}
- /*
- * close the index relation
- */
- index_endscan(scandesc);
- index_close(indexRelation);
-
/* must provide our own instrumentation support */
if (node->ss.ps.instrument)
InstrStopNodeMulti(node->ss.ps.instrument, nTuples);
* ExecBitmapIndexReScan(node)
*
* Recalculates the value of the scan keys whose value depends on
- * information known at runtime.
+ * information known at runtime and rescans the indexed relation.
* ----------------------------------------------------------------
*/
void
node->biss_NumScanKeys);
node->biss_RuntimeKeysReady = true;
}
+
+ /* reset index scan */
+ index_rescan(node->biss_ScanDesc, node->biss_ScanKeys);
}
/* ----------------------------------------------------------------
void
ExecEndBitmapIndexScan(BitmapIndexScanState *node)
{
+ Relation indexRelationDesc;
+ IndexScanDesc indexScanDesc;
+
+ /*
+ * extract information from the node
+ */
+ indexRelationDesc = node->biss_RelationDesc;
+ indexScanDesc = node->biss_ScanDesc;
+
/*
* Free the exprcontext ... now dead code, see ExecFreeExprContext
*/
if (node->biss_RuntimeContext)
FreeExprContext(node->biss_RuntimeContext);
#endif
+
+ /*
+ * close the index relation
+ */
+ index_endscan(indexScanDesc);
+ index_close(indexRelationDesc);
}
/* ----------------------------------------------------------------
indexstate->biss_RuntimeContext = NULL;
}
- /* We don't keep the table or index open across calls */
+ /*
+ * We do not open or lock the base relation here. We assume that an
+ * ancestor BitmapHeapScan node is holding AccessShareLock on the
+ * heap relation throughout the execution of the plan tree.
+ */
+
indexstate->ss.ss_currentRelation = NULL;
indexstate->ss.ss_currentScanDesc = NULL;
+ /*
+ * open the index relation and initialize relation and scan
+ * descriptors. Note we acquire no locks here; the index machinery
+ * does its own locks and unlocks.
+ */
+ indexstate->biss_RelationDesc = index_open(node->indexid);
+ indexstate->biss_ScanDesc =
+ index_beginscan_multi(indexstate->biss_RelationDesc,
+ estate->es_snapshot,
+ numScanKeys,
+ scanKeys);
+
/*
* all done.
*/
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.130 2005/04/28 21:47:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.131 2005/05/05 03:37:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* that will be evaluated at runtime
* RuntimeContext expr context for evaling runtime Skeys
* RuntimeKeysReady true if runtime Skeys have been computed
+ * RelationDesc index relation descriptor
+ * ScanDesc index scan descriptor
* ----------------
*/
typedef struct BitmapIndexScanState
ExprState **biss_RuntimeKeyInfo;
ExprContext *biss_RuntimeContext;
bool biss_RuntimeKeysReady;
+ Relation biss_RelationDesc;
+ IndexScanDesc biss_ScanDesc;
} BitmapIndexScanState;
/* ----------------