@@ -241,10 +241,14 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk
241
241
matchedDataSize = int64 (cap (matched ))* rowSize + int64 (cap (matchedPtrs ))* rowPtrSize
242
242
lastChunkBufPointer * chunk.Chunk = nil
243
243
memDelta int64 = 0
244
+ needTrackMemUsage = cap (innerPtrs ) > signalCheckpointForJoin
244
245
)
245
246
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
+ }
248
252
c .chkBufSizeForOneProbe = 0
249
253
250
254
for i , ptr := range innerPtrs {
@@ -257,13 +261,13 @@ func (c *hashRowContainer) GetMatchedRowsAndPtrs(probeKey uint64, probeRow chunk
257
261
if err != nil {
258
262
return nil , nil , err
259
263
}
260
- if c .chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil {
264
+ if needTrackMemUsage && c .chkBuf != lastChunkBufPointer && lastChunkBufPointer != nil {
261
265
lastChunkSize := lastChunkBufPointer .MemoryUsage ()
262
266
c .chkBufSizeForOneProbe += lastChunkSize
263
267
memDelta += lastChunkSize
264
268
}
265
269
lastChunkBufPointer = c .chkBuf
266
- if i & signalCheckpointForJoin == 0 {
270
+ if needTrackMemUsage && ( i & signalCheckpointForJoin == ( signalCheckpointForJoin - 1 )) {
267
271
// Trigger Consume for checking the OOM Action signal
268
272
memDelta += int64 (cap (matched ))* rowSize + int64 (cap (matchedPtrs ))* rowPtrSize - matchedDataSize
269
273
matchedDataSize = int64 (cap (matched ))* rowSize + int64 (cap (matchedPtrs ))* rowPtrSize
0 commit comments