|
36 | 36 | #include "executor/nodeHashjoin.h" |
37 | 37 | #include "miscadmin.h" |
38 | 38 | #include "port/pg_bitutils.h" |
39 | | -#include "utils/dynahash.h" |
40 | 39 | #include "utils/lsyscache.h" |
41 | 40 | #include "utils/memutils.h" |
42 | 41 | #include "utils/syscache.h" |
@@ -340,7 +339,7 @@ MultiExecParallelHash(HashState *node) |
340 | 339 | */ |
341 | 340 | hashtable->curbatch = -1; |
342 | 341 | hashtable->nbuckets = pstate->nbuckets; |
343 | | - hashtable->log2_nbuckets = my_log2(hashtable->nbuckets); |
| 342 | + hashtable->log2_nbuckets = pg_ceil_log2_32(hashtable->nbuckets); |
344 | 343 | hashtable->totalTuples = pstate->total_tuples; |
345 | 344 |
|
346 | 345 | /* |
@@ -480,7 +479,7 @@ ExecHashTableCreate(HashState *state) |
480 | 479 | &nbuckets, &nbatch, &num_skew_mcvs); |
481 | 480 |
|
482 | 481 | /* nbuckets must be a power of 2 */ |
483 | | - log2_nbuckets = my_log2(nbuckets); |
| 482 | + log2_nbuckets = pg_ceil_log2_32(nbuckets); |
484 | 483 | Assert(nbuckets == (1 << log2_nbuckets)); |
485 | 484 |
|
486 | 485 | /* |
@@ -935,6 +934,13 @@ ExecChooseHashTableSize(double ntuples, int tupwidth, bool useskew, |
935 | 934 | Assert(nbuckets > 0); |
936 | 935 | Assert(nbatch > 0); |
937 | 936 |
|
| 937 | + /* |
| 938 | + * Cap nbuckets, for power of 2 calculations. This maximum is safe |
| 939 | + * for pg_ceil_log2_32(). |
| 940 | + */ |
| 941 | + if (nbuckets > PG_INT32_MAX / 2) |
| 942 | + nbuckets = PG_INT32_MAX / 2; |
| 943 | + |
938 | 944 | *numbuckets = nbuckets; |
939 | 945 | *numbatches = nbatch; |
940 | 946 | } |
@@ -3499,7 +3505,7 @@ ExecParallelHashTableSetCurrentBatch(HashJoinTable hashtable, int batchno) |
3499 | 3505 | dsa_get_address(hashtable->area, |
3500 | 3506 | hashtable->batches[batchno].shared->buckets); |
3501 | 3507 | hashtable->nbuckets = hashtable->parallel_state->nbuckets; |
3502 | | - hashtable->log2_nbuckets = my_log2(hashtable->nbuckets); |
| 3508 | + hashtable->log2_nbuckets = pg_ceil_log2_32(hashtable->nbuckets); |
3503 | 3509 | hashtable->current_chunk = NULL; |
3504 | 3510 | hashtable->current_chunk_shared = InvalidDsaPointer; |
3505 | 3511 | hashtable->batches[batchno].at_least_one_chunk = false; |
|
0 commit comments