Tweak order of operations in BitmapHeapNext() to avoid the case of prefetching
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 12 Jan 2009 16:00:41 +0000 (16:00 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 12 Jan 2009 16:00:41 +0000 (16:00 +0000)
the same page we are nanoseconds away from reading for real.  There should be
something left to do on the current page before we consider issuing a prefetch.

src/backend/executor/nodeBitmapHeapscan.c

index 2ef7b887ddf24ee7790ab710a154f04bd61e4416..dda33306d1ccd922cbf5c4d0c83cce5da7b2a1d1 100644 (file)
@@ -236,10 +236,22 @@ BitmapHeapNext(BitmapHeapScanState *node)
 #endif /* USE_PREFETCH */
                }
 
+               /*
+                * Out of range?  If so, nothing more to look at on this page
+                */
+               if (scan->rs_cindex < 0 || scan->rs_cindex >= scan->rs_ntuples)
+               {
+                       node->tbmres = tbmres = NULL;
+                       continue;
+               }
+
 #ifdef USE_PREFETCH
                /*
                 * We issue prefetch requests *after* fetching the current page
                 * to try to avoid having prefetching interfere with the main I/O.
+                * Also, this should happen only when we have determined there is
+                * still something to do on the current page, else we may uselessly
+                * prefetch the same page we are just about to request for real.
                 */
                if (prefetch_iterator)
                {
@@ -260,15 +272,6 @@ BitmapHeapNext(BitmapHeapScanState *node)
                }
 #endif /* USE_PREFETCH */
 
-               /*
-                * Out of range?  If so, nothing more to look at on this page
-                */
-               if (scan->rs_cindex < 0 || scan->rs_cindex >= scan->rs_ntuples)
-               {
-                       node->tbmres = tbmres = NULL;
-                       continue;
-               }
-
                /*
                 * Okay to fetch the tuple
                 */