From d3141e17a7155e3d07c8deba4a10c748a29ba1e6 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sun, 12 Jan 2025 09:09:20 +0200 Subject: [PATCH] Start with minimal prefetch distance to minimize prefetch overhead for exact or limited index scans --- src/backend/access/nbtree/nbtsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 19734aa862a..a47172c0ca1 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -1191,8 +1191,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) else if (!enable_indexscan_prefetch || !scan->heapRelation) so->prefetch_maximum = 0; /* disable prefetch */ - /* If key bounds are not specified, then we will scan the whole relation and it make sense to start with the largest possible prefetch distance */ - so->current_prefetch_distance = (keysCount == 0) ? so->prefetch_maximum : 0; + /* Start with minimal prefetch distance to minimize prefetch overhead for exact or limited index scans */ + so->current_prefetch_distance = 0; /* * If we found no usable boundary keys, we have to start from one end of