File tree Expand file tree Collapse file tree 1 file changed +6
-22
lines changed Expand file tree Collapse file tree 1 file changed +6
-22
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
19
19
"context"
20
20
"hash"
21
21
"math"
22
+ "math/bits"
22
23
"math/rand"
23
24
"runtime/trace"
24
25
"strconv"
@@ -311,32 +312,15 @@ func (hCtx *HashJoinCtxV2) resetHashTableContextForRestore() {
311
312
312
313
// partitionNumber is always power of 2
313
314
func genHashJoinPartitionNumber (partitionHint uint ) uint {
314
- prevRet := uint (16 )
315
- currentRet := uint (8 )
316
- for currentRet != 0 {
317
- if currentRet < partitionHint {
318
- return prevRet
319
- }
320
- prevRet = currentRet
321
- currentRet = currentRet >> 1
315
+ partitionNumber := uint (1 )
316
+ for partitionNumber < partitionHint && partitionNumber < 16 {
317
+ partitionNumber <<= 1
322
318
}
323
- return 1
319
+ return partitionNumber
324
320
}
325
321
326
322
func getPartitionMaskOffset (partitionNumber uint ) int {
327
- getMSBPos := func (num uint64 ) int {
328
- ret := 0
329
- for num & 1 != 1 {
330
- num = num >> 1
331
- ret ++
332
- }
333
- if num != 1 {
334
- // partitionNumber is always pow of 2
335
- panic ("should not reach here" )
336
- }
337
- return ret
338
- }
339
- msbPos := getMSBPos (uint64 (partitionNumber ))
323
+ msbPos := bits .TrailingZeros64 (uint64 (partitionNumber ))
340
324
// top MSB bits in hash value will be used to partition data
341
325
return 64 - msbPos
342
326
}
You can’t perform that action at this time.
0 commit comments