From 6dd4f7a66425a2aa452b51fbe1c95bbfb7c9e893 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 18 Mar 2008 03:54:52 +0000 Subject: [PATCH] Advance multiple array keys rightmost-first instead of leftmost-first 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index b3ebc9b3d2..198bb92686 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -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; -- 2.39.5