Skip to content

Commit b314a9c

Browse files
authored
executor: minor refine of hash join v2 (#57023)
ref #53127
1 parent a22fc59 commit b314a9c

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

pkg/executor/join/hash_join_v2.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"hash"
2121
"math"
22+
"math/bits"
2223
"math/rand"
2324
"runtime/trace"
2425
"strconv"
@@ -311,32 +312,15 @@ func (hCtx *HashJoinCtxV2) resetHashTableContextForRestore() {
311312

312313
// partitionNumber is always power of 2
313314
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
322318
}
323-
return 1
319+
return partitionNumber
324320
}
325321

326322
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))
340324
// top MSB bits in hash value will be used to partition data
341325
return 64 - msbPos
342326
}

0 commit comments

Comments
 (0)