Skip to content

Commit eff883d

Browse files
committed
executor: fix unreasonable CPU time in HashJoin probe phash (pingcap#41265)
close pingcap#41263
1 parent 59b8ad2 commit eff883d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

executor/hash_table.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,14 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk
241241
matchedDataSize = int64(cap(matched))*rowSize + int64(cap(matchedPtrs))*rowPtrSize
242242
lastChunkBufPointer *chunk.Chunk = nil
243243
memDelta int64 = 0
244+
needTrackMemUsage = cap(innerPtrs) > signalCheckpointForJoin
244245
)
245246
c.chkBuf = nil
246-
c.memTracker.Consume(-c.chkBufSizeForOneProbe + int64(cap(innerPtrs))*rowPtrSize)
247-
defer c.memTracker.Consume(-int64(cap(innerPtrs))*rowPtrSize + memDelta)
247+
c.memTracker.Consume(-c.chkBufSizeForOneProbe)
248+
if needTrackMemUsage {
249+
c.memTracker.Consume(int64(cap(innerPtrs)) * rowPtrSize)
250+
defer c.memTracker.Consume(-int64(cap(innerPtrs))*rowPtrSize + memDelta)
251+
}
248252
c.chkBufSizeForOneProbe = 0
249253

250254
for i, ptr := range innerPtrs {
@@ -257,13 +261,13 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk
257261
if err != nil {
258262
return nil, nil, err
259263
}
260-
if c.chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil {
264+
if needTrackMemUsage && c.chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil {
261265
lastChunkSize := lastChunkBufPointer.MemoryUsage()
262266
c.chkBufSizeForOneProbe += lastChunkSize
263267
memDelta += lastChunkSize
264268
}
265269
lastChunkBufPointer = c.chkBuf
266-
if i&signalCheckpointForJoin == 0 {
270+
if needTrackMemUsage && (i&signalCheckpointForJoin == (signalCheckpointForJoin - 1)) {
267271
// Trigger Consume for checking the OOM Action signal
268272
memDelta += int64(cap(matched))*rowSize + int64(cap(matchedPtrs))*rowPtrSize - matchedDataSize
269273
matchedDataSize = int64(cap(matched))*rowSize + int64(cap(matchedPtrs))*rowPtrSize

0 commit comments

Comments
 (0)