diff --git a/executor/aggregate.go b/executor/aggregate.go index 5313ef54793af..1dd38edf2be3d 100644 --- a/executor/aggregate.go +++ b/executor/aggregate.go @@ -141,41 +141,6 @@ func (e *HashAggExec) execute(ctx context.Context) (err error) { } } -// Next implements the Executor Next interface. -func (e *HashAggExec) Next(ctx context.Context) (Row, error) { - // In this stage we consider all data from src as a single group. - if !e.executed { - for { - hasMore, err := e.innerNext(ctx) - if err != nil { - return nil, errors.Trace(err) - } - if !hasMore { - break - } - } - if (e.groupMap.Len() == 0) && len(e.GroupByItems) == 0 { - // If no groupby and no data, we should add an empty group. - // For example: - // "select count(c) from t;" should return one row [0] - // "select count(c) from t group by c1;" should return empty result set. - e.groupMap.Put([]byte{}, []byte{}) - } - e.executed = true - } - - groupKey, _ := e.groupIterator.Next() - if groupKey == nil { - return nil, nil - } - retRow := make([]types.Datum, 0, len(e.AggFuncs)) - aggCtxs := e.getContexts(groupKey) - for i, af := range e.AggFuncs { - retRow = append(retRow, af.GetResult(aggCtxs[i])) - } - return retRow, nil -} - func (e *HashAggExec) getGroupKey(row types.Row) ([]byte, error) { vals := make([]types.Datum, 0, len(e.GroupByItems)) for _, item := range e.GroupByItems { @@ -196,34 +161,6 @@ func (e *HashAggExec) getGroupKey(row types.Row) ([]byte, error) { return e.groupKey, nil } -// innerNext fetches a single row from src and update each aggregate function. -// If the first return value is false, it means there is no more data from src. -func (e *HashAggExec) innerNext(ctx context.Context) (ret bool, err error) { - srcRow, err := e.children[0].Next(ctx) - if err != nil { - return false, errors.Trace(err) - } - if srcRow == nil { - return false, nil - } - e.executed = true - groupKey, err := e.getGroupKey(srcRow) - if err != nil { - return false, errors.Trace(err) - } - if len(e.groupMap.Get(groupKey, e.groupVals[:0])) == 0 { - e.groupMap.Put(groupKey, []byte{}) - } - aggCtxs := e.getContexts(groupKey) - for i, af := range e.AggFuncs { - err = af.Update(aggCtxs[i], e.sc, srcRow) - if err != nil { - return false, errors.Trace(err) - } - } - return true, nil -} - func (e *HashAggExec) getContexts(groupKey []byte) []*aggregation.AggEvaluateContext { groupKeyString := string(groupKey) aggCtxs, ok := e.aggCtxsMap[groupKeyString]