Skip to content

Commit

Permalink
executor: fix unreasonable CPU time in HashJoin probe phash (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 authored and blacktear23 committed Feb 15, 2023
1 parent d63c6dc commit e62f216
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions executor/hash_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,14 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk
matchedDataSize = int64(cap(matched))*rowSize + int64(cap(matchedPtrs))*rowPtrSize
lastChunkBufPointer *chunk.Chunk = nil
memDelta int64 = 0
needTrackMemUsage = cap(innerPtrs) > signalCheckpointForJoin
)
c.chkBuf = nil
c.memTracker.Consume(-c.chkBufSizeForOneProbe + int64(cap(innerPtrs))*rowPtrSize)
defer c.memTracker.Consume(-int64(cap(innerPtrs))*rowPtrSize + memDelta)
c.memTracker.Consume(-c.chkBufSizeForOneProbe)
if needTrackMemUsage {
c.memTracker.Consume(int64(cap(innerPtrs)) * rowPtrSize)
defer c.memTracker.Consume(-int64(cap(innerPtrs))*rowPtrSize + memDelta)
}
c.chkBufSizeForOneProbe = 0

for i, ptr := range innerPtrs {
Expand All @@ -257,13 +261,13 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk
if err != nil {
return nil, nil, err
}
if c.chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil {
if needTrackMemUsage && c.chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil {
lastChunkSize := lastChunkBufPointer.MemoryUsage()
c.chkBufSizeForOneProbe += lastChunkSize
memDelta += lastChunkSize
}
lastChunkBufPointer = c.chkBuf
if i&signalCheckpointForJoin == 0 {
if needTrackMemUsage && (i&signalCheckpointForJoin == (signalCheckpointForJoin - 1)) {
// Trigger Consume for checking the OOM Action signal
memDelta += int64(cap(matched))*rowSize + int64(cap(matchedPtrs))*rowPtrSize - matchedDataSize
matchedDataSize = int64(cap(matched))*rowSize + int64(cap(matchedPtrs))*rowPtrSize
Expand Down

0 comments on commit e62f216

Please sign in to comment.