]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Advance multiple array keys rightmost-first instead of leftmost-first
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Mar 2008 03:54:52 +0000 (03:54 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Mar 2008 03:54:52 +0000 (03:54 +0000)
during a bitmap index scan.  This cannot affect the query results
(since we're just dumping the TIDs into a bitmap) but it might offer
some advantage in locality of access to the index.  Per Greg Stark.

src/backend/executor/nodeIndexscan.c

index 2db4015504ed69664bb4e00f2674af693cd021e8..59f54ee5cb42c75cbc1143a4f3016a9806c5b826 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.125 2008/01/01 19:45:49 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.126 2008/03/18 03:54:52 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -352,7 +352,13 @@ ExecIndexAdvanceArrayKeys(IndexArrayKeyInfo *arrayKeys, int numArrayKeys)
        bool            found = false;
        int                     j;
 
-       for (j = 0; j < numArrayKeys; j++)
+       /*
+        * Note we advance the rightmost array key most quickly, since it will
+        * correspond to the lowest-order index column among the available
+        * qualifications.  This is hypothesized to result in better locality
+        * of access in the index.
+        */
+       for (j = numArrayKeys - 1; j >= 0; j--)
        {
                ScanKey         scan_key = arrayKeys[j].scan_key;
                int                     next_elem = arrayKeys[j].next_elem;