diff --git a/executor/aggregate.go b/executor/aggregate.go index 57aa431f718a6..ff3a6f7aa72b3 100644 --- a/executor/aggregate.go +++ b/executor/aggregate.go @@ -161,6 +161,7 @@ type HashAggExec struct { isChildReturnEmpty bool childResult *chunk.Chunk + executed bool } // HashAggInput indicates the input of hash agg exec. @@ -214,6 +215,7 @@ func (e *HashAggExec) Close() error { } for range e.finalOutputCh { } + e.executed = false return e.baseExecutor.Close() } @@ -602,10 +604,14 @@ func (e *HashAggExec) parallelExec(ctx context.Context, chk *chunk.Chunk) error e.prepared = true } + if e.executed { + return nil + } for !chk.IsFull() { e.finalInputCh <- chk result, ok := <-e.finalOutputCh if !ok { // all finalWorkers exited + e.executed = true if chk.NumRows() > 0 { // but there are some data left return nil }