Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions pkg/executor/aggregate/agg_hash_partial_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,16 @@ type HashAggPartialWorker struct {
inflightChunkSync *sync.WaitGroup
}

func (w *HashAggPartialWorker) getChildInput() bool {
func (w *HashAggPartialWorker) getChildInput() (*chunk.Chunk, bool) {
select {
case <-w.finishCh:
return false
return nil, false
case chk, ok := <-w.inputCh:
if !ok {
return false
}

sizeBefore := w.chk.MemoryUsage()
w.chk.SwapColumns(chk)
w.memTracker.Consume(w.chk.MemoryUsage() - sizeBefore)

w.giveBackCh <- &HashAggInput{
chk: chk,
giveBackCh: w.inputCh,
return nil, false
}
return chk, true
}
return true
}

func (w *HashAggPartialWorker) fetchChunkAndProcess(ctx sessionctx.Context, hasError *bool, needShuffle *bool) bool {
Expand All @@ -99,7 +90,7 @@ func (w *HashAggPartialWorker) fetchChunkAndProcess(ctx sessionctx.Context, hasE
}

waitStart := time.Now()
ok := w.getChildInput()
chk, ok := w.getChildInput()
updateWaitTime(w.stats, waitStart)

if !ok {
Expand All @@ -108,6 +99,17 @@ func (w *HashAggPartialWorker) fetchChunkAndProcess(ctx sessionctx.Context, hasE

defer w.inflightChunkSync.Done()

w.intestDuringPartialWorkerRun()

sizeBefore := w.chk.MemoryUsage()
w.chk.SwapColumns(chk)
w.memTracker.Consume(w.chk.MemoryUsage() - sizeBefore)

w.giveBackCh <- &HashAggInput{
chk: chk,
giveBackCh: w.inputCh,
}

execStart := time.Now()
if err := w.updatePartialResult(ctx, w.chk, len(w.partialResultsMap)); err != nil {
*hasError = true
Expand Down