Fix HashAgg regression from choosing too many initial buckets.
authorJeff Davis <jdavis@postgresql.org>
Tue, 9 Jun 2020 03:59:45 +0000 (20:59 -0700)
committerJeff Davis <jdavis@postgresql.org>
Tue, 9 Jun 2020 04:04:16 +0000 (21:04 -0700)
Diagnosis by Andres.

Reported-by: Pavel Stehule
Discussion: https://postgr.es/m/CAFj8pRDLVakD5Aagt3yZeEQeTeEWaS3YE5h8XC3Q3qJ6TYkc2Q%40mail.gmail.com
Backpatch-through: 13

src/backend/executor/nodeAgg.c

index 26111327ca157b3debaa5c34336ee92ae90424e2..331acee28141202b8a6aa620861347a4f3405422 100644 (file)
 #define HASHAGG_READ_BUFFER_SIZE BLCKSZ
 #define HASHAGG_WRITE_BUFFER_SIZE BLCKSZ
 
-/* minimum number of initial hash table buckets */
-#define HASHAGG_MIN_BUCKETS 256
-
 /*
  * Estimate chunk overhead as a constant 16 bytes. XXX: should this be
  * improved?
@@ -1926,9 +1923,8 @@ hash_choose_num_buckets(double hashentrysize, long ngroups, Size memory)
 
    if (nbuckets > max_nbuckets)
        nbuckets = max_nbuckets;
-   if (nbuckets < HASHAGG_MIN_BUCKETS)
-       nbuckets = HASHAGG_MIN_BUCKETS;
-   return nbuckets;
+
+   return Max(nbuckets, 1);
 }
 
 /*