From 656074aef07cca431e68b833c98790ffebf83bef Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Mon, 9 May 2022 15:16:33 +0800 Subject: [PATCH] cherry pick #34418 to release-5.1 Signed-off-by: ti-srebot --- executor/index_lookup_hash_join.go | 4 ++++ executor/index_lookup_join.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/executor/index_lookup_hash_join.go b/executor/index_lookup_hash_join.go index 5dd6f960811f6..b84c0f539db6c 100644 --- a/executor/index_lookup_hash_join.go +++ b/executor/index_lookup_hash_join.go @@ -489,6 +489,10 @@ func (iw *indexHashJoinInnerWorker) run(ctx context.Context, cancelFunc context. } h, resultCh := fnv.New64(), iw.resultCh for { + // The previous task has been processed, so release the occupied memory + if task != nil { + task.memTracker.Detach() + } select { case <-ctx.Done(): return diff --git a/executor/index_lookup_join.go b/executor/index_lookup_join.go index 440b223a9f770..fe1c2423daf35 100644 --- a/executor/index_lookup_join.go +++ b/executor/index_lookup_join.go @@ -310,6 +310,10 @@ func (e *IndexLookUpJoin) getFinishedTask(ctx context.Context) (*lookUpJoinTask, return task, nil } + // The previous task has been processed, so release the occupied memory + if task != nil { + task.memTracker.Detach() + } select { case task = <-e.resultCh: case <-ctx.Done(): @@ -556,7 +560,7 @@ func (iw *innerWorker) constructLookupContent(task *lookUpJoinTask) ([]*indexJoi return nil, err } if rowIdx == 0 { - iw.lookup.memTracker.Consume(types.EstimatedMemUsage(dLookUpKey, numRows)) + iw.memTracker.Consume(types.EstimatedMemUsage(dLookUpKey, numRows)) } if dHashKey == nil { // Append null to make looUpKeys the same length as outer Result.