Skip to content

Commit

Permalink
executor: minor refine of hash join v2 (#57023)
Browse files Browse the repository at this point in the history
ref #53127
  • Loading branch information
windtalker authored Oct 31, 2024
1 parent a22fc59 commit b314a9c
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions pkg/executor/join/hash_join_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"hash"
"math"
"math/bits"
"math/rand"
"runtime/trace"
"strconv"
Expand Down Expand Up @@ -311,32 +312,15 @@ func (hCtx *HashJoinCtxV2) resetHashTableContextForRestore() {

// partitionNumber is always power of 2
func genHashJoinPartitionNumber(partitionHint uint) uint {
prevRet := uint(16)
currentRet := uint(8)
for currentRet != 0 {
if currentRet < partitionHint {
return prevRet
}
prevRet = currentRet
currentRet = currentRet >> 1
partitionNumber := uint(1)
for partitionNumber < partitionHint && partitionNumber < 16 {
partitionNumber <<= 1
}
return 1
return partitionNumber
}

func getPartitionMaskOffset(partitionNumber uint) int {
getMSBPos := func(num uint64) int {
ret := 0
for num&1 != 1 {
num = num >> 1
ret++
}
if num != 1 {
// partitionNumber is always pow of 2
panic("should not reach here")
}
return ret
}
msbPos := getMSBPos(uint64(partitionNumber))
msbPos := bits.TrailingZeros64(uint64(partitionNumber))
// top MSB bits in hash value will be used to partition data
return 64 - msbPos
}
Expand Down

0 comments on commit b314a9c

Please sign in to comment.