* Choose a reasonable number of buckets for the initial hash table size. */
| 2121 | * Choose a reasonable number of buckets for the initial hash table size. |
| 2122 | */ |
| 2123 | static long |
| 2124 | hash_choose_num_buckets(double hashentrysize, long ngroups, Size memory) |
| 2125 | { |
| 2126 | long max_nbuckets; |
| 2127 | long nbuckets = ngroups; |
| 2128 | |
| 2129 | max_nbuckets = memory / hashentrysize; |
| 2130 | |
| 2131 | /* |
| 2132 | * Underestimating is better than overestimating. Too many buckets crowd |
| 2133 | * out space for group keys and transition state values. |
| 2134 | */ |
| 2135 | max_nbuckets >>= 1; |
| 2136 | |
| 2137 | if (nbuckets > max_nbuckets) |
| 2138 | nbuckets = max_nbuckets; |
| 2139 | |
| 2140 | return Max(nbuckets, 1); |
| 2141 | } |
| 2142 | |
| 2143 | /* |
| 2144 | * Determine the number of partitions to create when spilling, which will |