88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.7 2005/04/25 01:30:12 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.8 2005/05/05 03:37:23 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -38,8 +38,6 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
3838{
3939#define MAX_TIDS 1024
4040TIDBitmap * tbm ;
41- Oid indexid ;
42- Relation indexRelation ;
4341IndexScanDesc scandesc ;
4442ItemPointerData tids [MAX_TIDS ];
4543int32 ntids ;
@@ -49,31 +47,18 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
4947if (node -> ss .ps .instrument )
5048InstrStartNode (node -> ss .ps .instrument );
5149
50+ /*
51+ * extract necessary information from index scan node
52+ */
53+ scandesc = node -> biss_ScanDesc ;
54+
5255/*
5356 * If we have runtime keys and they've not already been set up, do it
5457 * now.
5558 */
5659if (node -> biss_RuntimeKeyInfo && !node -> biss_RuntimeKeysReady )
5760ExecReScan ((PlanState * )node ,NULL );
5861
59- /*
60- * We do not open or lock the base relation here. We assume that an
61- * ancestor BitmapHeapScan node is holding AccessShareLock on the
62- * heap relation throughout the execution of the plan tree.
63- */
64-
65- /*
66- * open the index relation and initialize relation and scan
67- * descriptors. Note we acquire no locks here; the index machinery
68- * does its own locks and unlocks.
69- */
70- indexid = ((BitmapIndexScan * )node -> ss .ps .plan )-> indexid ;
71- indexRelation = index_open (indexid );
72- scandesc = index_beginscan_multi (indexRelation ,
73- node -> ss .ps .state -> es_snapshot ,
74- node -> biss_NumScanKeys ,
75- node -> biss_ScanKeys );
76-
7762/*
7863 * Prepare the result bitmap. Normally we just create a new one to pass
7964 * back; however, our parent node is allowed to store a pre-made one
@@ -110,12 +95,6 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
11095CHECK_FOR_INTERRUPTS ();
11196}
11297
113- /*
114- * close the index relation
115- */
116- index_endscan (scandesc );
117- index_close (indexRelation );
118-
11998/* must provide our own instrumentation support */
12099if (node -> ss .ps .instrument )
121100InstrStopNodeMulti (node -> ss .ps .instrument ,nTuples );
@@ -127,7 +106,7 @@ MultiExecBitmapIndexScan(BitmapIndexScanState *node)
127106 *ExecBitmapIndexReScan(node)
128107 *
129108 *Recalculates the value of the scan keys whose value depends on
130- *information known at runtime.
109+ *information known at runtime and rescans the indexed relation .
131110 * ----------------------------------------------------------------
132111 */
133112void
@@ -169,6 +148,9 @@ ExecBitmapIndexReScan(BitmapIndexScanState *node, ExprContext *exprCtxt)
169148node -> biss_NumScanKeys );
170149node -> biss_RuntimeKeysReady = true;
171150}
151+
152+ /* reset index scan */
153+ index_rescan (node -> biss_ScanDesc ,node -> biss_ScanKeys );
172154}
173155
174156/* ----------------------------------------------------------------
@@ -178,13 +160,28 @@ ExecBitmapIndexReScan(BitmapIndexScanState *node, ExprContext *exprCtxt)
178160void
179161ExecEndBitmapIndexScan (BitmapIndexScanState * node )
180162{
163+ Relation indexRelationDesc ;
164+ IndexScanDesc indexScanDesc ;
165+
166+ /*
167+ * extract information from the node
168+ */
169+ indexRelationDesc = node -> biss_RelationDesc ;
170+ indexScanDesc = node -> biss_ScanDesc ;
171+
181172/*
182173 * Free the exprcontext ... now dead code, see ExecFreeExprContext
183174 */
184175#ifdef NOT_USED
185176if (node -> biss_RuntimeContext )
186177FreeExprContext (node -> biss_RuntimeContext );
187178#endif
179+
180+ /*
181+ * close the index relation
182+ */
183+ index_endscan (indexScanDesc );
184+ index_close (indexRelationDesc );
188185}
189186
190187/* ----------------------------------------------------------------
@@ -272,10 +269,27 @@ ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate)
272269indexstate -> biss_RuntimeContext = NULL ;
273270}
274271
275- /* We don't keep the table or index open across calls */
272+ /*
273+ * We do not open or lock the base relation here. We assume that an
274+ * ancestor BitmapHeapScan node is holding AccessShareLock on the
275+ * heap relation throughout the execution of the plan tree.
276+ */
277+
276278indexstate -> ss .ss_currentRelation = NULL ;
277279indexstate -> ss .ss_currentScanDesc = NULL ;
278280
281+ /*
282+ * open the index relation and initialize relation and scan
283+ * descriptors. Note we acquire no locks here; the index machinery
284+ * does its own locks and unlocks.
285+ */
286+ indexstate -> biss_RelationDesc = index_open (node -> indexid );
287+ indexstate -> biss_ScanDesc =
288+ index_beginscan_multi (indexstate -> biss_RelationDesc ,
289+ estate -> es_snapshot ,
290+ numScanKeys ,
291+ scanKeys );
292+
279293/*
280294 * all done.
281295 */