diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 2551df8a671..fff7c89eadb 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -896,8 +896,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) Assert(!BTScanPosIsValid(so->currPos)); - pgstat_count_index_scan(rel); - /* * Examine the scan keys and eliminate any redundant keys; also mark the * keys that must be matched to continue the scan. @@ -960,6 +958,12 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) _bt_start_array_keys(scan, dir); } + /* + * Count an indexscan for stats, now that we know that we'll call + * _bt_search/_bt_endpoint below + */ + pgstat_count_index_scan(rel); + /*---------- * Examine the scan keys to discover where we need to start the scan. *