diff --git a/executor/aggregate.go b/executor/aggregate.go index bcba95859299d..f9c40afb8f7eb 100644 --- a/executor/aggregate.go +++ b/executor/aggregate.go @@ -523,6 +523,7 @@ func getGroupKey(ctx sessionctx.Context, input *chunk.Chunk, groupKey [][]byte, func (w *baseHashAggWorker) getPartialResult(sc *stmtctx.StatementContext, groupKey [][]byte, mapper aggPartialResultMapper) [][]aggfuncs.PartialResult { n := len(groupKey) partialResults := make([][]aggfuncs.PartialResult, n) + allMemDelta := int64(0) for i := 0; i < n; i++ { var ok bool if partialResults[i], ok = mapper[string(groupKey[i])]; ok { @@ -531,16 +532,17 @@ func (w *baseHashAggWorker) getPartialResult(sc *stmtctx.StatementContext, group for _, af := range w.aggFuncs { partialResult, memDelta := af.AllocPartialResult() partialResults[i] = append(partialResults[i], partialResult) - w.memTracker.Consume(memDelta) + allMemDelta += memDelta } mapper[string(groupKey[i])] = partialResults[i] - w.memTracker.Consume(int64(len(groupKey[i]))) + allMemDelta += int64(len(groupKey[i])) // Map will expand when count > bucketNum * loadFactor. The memory usage will doubled. if len(mapper) > (1<