From b1379a61b5b5c8d332c3dc6d65d2a93020568aa1 Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Mon, 9 May 2022 15:16:33 +0800 Subject: [PATCH] executor: release memory usage of task in indexJoin/indexHashJoin (#34418) close pingcap/tidb#34417 --- 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 51f21c2491e77..5287f43a59cbe 100644 --- a/executor/index_lookup_hash_join.go +++ b/executor/index_lookup_hash_join.go @@ -464,6 +464,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 6961a22a5c8ab..06d04746b8925 100644 --- a/executor/index_lookup_join.go +++ b/executor/index_lookup_join.go @@ -318,6 +318,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(): @@ -559,7 +563,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 lookUpKeys the same length as outer Result.