88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.65 2001/11/12 17:18:06 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.66 2002/02/11 20:10:48 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -301,24 +301,13 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
301301 IndexScanState * indexstate ;
302302 ExprContext * econtext ;
303303 ScanDirection direction ;
304+ int numIndices ;
304305 IndexScanDescPtr scanDescs ;
305306 ScanKey * scanKeys ;
306- IndexScanDesc scan ;
307- ScanKey skey ;
308- int numIndices ;
309- int i ;
310307 int * * runtimeKeyInfo ;
311308 int * numScanKeys ;
312- List * indxqual ;
313- List * qual ;
314- int n_keys ;
315- ScanKey scan_keys ;
316- int * run_keys ;
309+ int i ;
317310 int j ;
318- Expr * clause ;
319- Node * scanexpr ;
320- Datum scanvalue ;
321- bool isNull ;
322311
323312 estate = node -> scan .plan .state ;
324313 indexstate = node -> indxstate ;
@@ -330,10 +319,6 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
330319 scanKeys = indexstate -> iss_ScanKeys ;
331320 runtimeKeyInfo = indexstate -> iss_RuntimeKeyInfo ;
332321 numScanKeys = indexstate -> iss_NumScanKeys ;
333- if (ScanDirectionIsBackward (node -> indxorderdir ))
334- indexstate -> iss_IndexPtr = numIndices ;
335- else
336- indexstate -> iss_IndexPtr = -1 ;
337322
338323 if (econtext )
339324 {
@@ -359,28 +344,27 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
359344 ResetExprContext (econtext );
360345 }
361346
362- /* If this is re-scanning of PlanQual ... */
363- if (estate -> es_evTuple != NULL &&
364- estate -> es_evTuple [node -> scan .scanrelid - 1 ] != NULL )
365- {
366- estate -> es_evTupleNull [node -> scan .scanrelid - 1 ] = false;
367- return ;
368- }
369-
370347 /*
371- * get the index qualifications and recalculate the appropriate values
348+ * If we are doing runtime key calculations (ie, the index keys depend
349+ * on data from an outer scan), compute the new key values
372350 */
373- indxqual = node -> indxqual ;
374- for (i = 0 ; i < numIndices ; i ++ )
351+ if (runtimeKeyInfo )
375352 {
376- qual = lfirst (indxqual );
377- indxqual = lnext (indxqual );
378- n_keys = numScanKeys [i ];
379- scan_keys = (ScanKey ) scanKeys [i ];
353+ List * indxqual ;
380354
381- if (runtimeKeyInfo )
355+ indxqual = node -> indxqual ;
356+ for (i = 0 ; i < numIndices ; i ++ )
382357 {
358+ List * qual = lfirst (indxqual );
359+ int n_keys ;
360+ ScanKey scan_keys ;
361+ int * run_keys ;
362+
363+ indxqual = lnext (indxqual );
364+ n_keys = numScanKeys [i ];
365+ scan_keys = scanKeys [i ];
383366 run_keys = runtimeKeyInfo [i ];
367+
384368 for (j = 0 ; j < n_keys ; j ++ )
385369 {
386370 /*
@@ -398,7 +382,11 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
398382 */
399383 if (run_keys [j ] != NO_OP )
400384 {
401- clause = nth (j , qual );
385+ Expr * clause = nth (j , qual );
386+ Node * scanexpr ;
387+ Datum scanvalue ;
388+ bool isNull ;
389+
402390 scanexpr = (run_keys [j ] == RIGHT_OP ) ?
403391 (Node * ) get_rightop (clause ) :
404392 (Node * ) get_leftop (clause );
@@ -415,13 +403,31 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
415403 }
416404 }
417405 }
418- scan = scanDescs [i ];
419- skey = scanKeys [i ];
420- index_rescan (scan , direction , skey );
421- }
422406
423- if (runtimeKeyInfo )
424407 indexstate -> iss_RuntimeKeysReady = true;
408+ }
409+
410+ /* If this is re-scanning of PlanQual ... */
411+ if (estate -> es_evTuple != NULL &&
412+ estate -> es_evTuple [node -> scan .scanrelid - 1 ] != NULL )
413+ {
414+ estate -> es_evTupleNull [node -> scan .scanrelid - 1 ] = false;
415+ return ;
416+ }
417+
418+ /* reset index scans */
419+ if (ScanDirectionIsBackward (node -> indxorderdir ))
420+ indexstate -> iss_IndexPtr = numIndices ;
421+ else
422+ indexstate -> iss_IndexPtr = -1 ;
423+
424+ for (i = 0 ; i < numIndices ; i ++ )
425+ {
426+ IndexScanDesc scan = scanDescs [i ];
427+ ScanKey skey = scanKeys [i ];
428+
429+ index_rescan (scan , direction , skey );
430+ }
425431}
426432
427433/* ----------------------------------------------------------------
0 commit comments