// Next returns the next Result in the sorted, merged stream.
// It is part of the ResultReader interface.
335559
func (rm *ResultMerger) Next() (*sqltypes.Result, error) {
	// All input readers were consumed during a merge. Return end of stream.
	if len(rm.inputs) == 0 {
		return nil, io.EOF
	}
	// Endgame mode if there is exactly one input left.
	if len(rm.inputs) == 1 && rm.lastRowReaderDrained {
		return rm.inputs[0].Next()
	}

	// Current output buffer is not full and there is more than one input left.
	// Keep merging rows from the inputs using the priority queue.
	for len(rm.output) < ResultSizeRows && len(rm.inputs) != 0 {
		// Get the next smallest row.
		next := heap.Pop(rm.nextRowHeap).(*nextRow)
		// Add it to the output.
		rm.output = append(rm.output, next.row)
		// Check if the input we just popped has more rows.
		if err := next.next(); err != nil {
			if err == io.EOF {
				// No more rows. Delete this input ResultReader from "inputs".
				rm.deleteInput(next.input)

				if len(rm.inputs) == 1 {
					// We just deleted the second last ResultReader from "inputs" i.e.
					// only one input is left. Tell the last input's RowReader to stop
					// processing new Results after the current Result. Once we read the
					// remaining rows, we can switch to the endgame mode where we read the
					// Result directly from the input.
					lastNextRow := heap.Pop(rm.nextRowHeap).(*nextRow)
					lastNextRow.rowReader.StopAfterCurrentResult()
					heap.Push(rm.nextRowHeap, lastNextRow)
				}

				// Do not add back the deleted input to the priority queue.
				continue
			} else if err == ErrStoppedRowReader {
				// Endgame mode: We just consumed all rows from the last input.
				// Switch to a faster mode where we read Results from the input instead
				// of reading rows from the RowReader.
				rm.lastRowReaderDrained = true
				break
			} else {
				return nil, vterrors.Wrapf(err, "failed to read from input ResultReader: %v err", next.input)
			}
		}
		// Input has more rows. Add it back to the priority queue.
		heap.Push(rm.nextRowHeap, next)
	}

	result := &sqltypes.Result{
		Fields:       rm.fields,
		RowsAffected: uint64(len(rm.output)),
		Rows:         rm.output,
	}
	rm.reset()

	return result, nil
}
779134
func (s *sequences) next(seq string) int {
	if s.s == nil {
		s.s = make(map[string]int, 1)
	}
	v := s.s[seq] + 1
	s.s[seq] = v
	return v
}
735728
func (c *C) Next() {
	c.index++
	s := int8(len(c.handlers))
	if c.index < s {
		c.handlers[c.index](c)
	}
}
1035414
func (i *Int8) Next() int8 {
	i.lock.Lock()
	defer i.lock.Unlock()
	i.increment++
	return i.increment
}
1303934
func (i *Int32) Next() int32 {
	i.lock.Lock()
	defer i.lock.Unlock()
	i.increment++
	return i.increment
}
873089
func (s *ApplicationStream) Next() (*Application, error) {
	var application Application
	if s.decoder.More() {
		err := s.decoder.Decode(&application)
		return &application, err
	}

	// parse last token
	_, err := s.decoder.Token()
	if err != nil {
		return nil, err
	}

	return nil, io.EOF
}
255066
func (r *Reader) Next() (p Packet, err error) {
	if len(r.q) > 0 {
		p = r.q[len(r.q)-1]
		r.q = r.q[:len(r.q)-1]
		return
	}

	for len(r.readers) > 0 {
		p, err = Read(r.readers[len(r.readers)-1])
		if err == nil {
			return
		}
		if err == io.EOF {
			r.readers = r.readers[:len(r.readers)-1]
			continue
		}
		if _, ok := err.(errors.UnknownPacketTypeError); !ok {
			return nil, err
		}
	}

	return nil, io.EOF
}
898703
func (s Slice) Next() (Slice, error) {
	size, err := s.ByteSize()
	if err != nil {
		return nil, WithStack(err)
	}
	return Slice(s[size:]), nil
}
761818
func (iter *CombinationIterator) Next() []interface{} {
	if !iter.HasNext() {
		return nil
	}

	if iter.res[0] != nil {
		i := iter.r - 1
		for ; i > -1; i-- {
			if iter.indices[i] != i+iter.n-iter.r {
				break
			}
		}
		if i > -1 {
			iter.indices[i] += 1
			for j := i + 1; j < iter.r; j++ {
				iter.indices[j] = iter.indices[j-1] + 1
			}
		}
	}

	for j := 0; j < iter.r; j++ {
		iter.res[j] = iter.pool[iter.indices[j]]
	}

	iter.iters += 1

	return iter.res
}
67325
func (rr *RowReader) Next() ([]sqltypes.Value, error) {
	for rr.currentResult == nil || rr.currentIndex == len(rr.currentResult.Rows) {
		if rr.stopAfterCurrentResult {
			return nil, ErrStoppedRowReader
		}

		var err error
		rr.currentResult, err = rr.resultReader.Next()
		if err != nil {
			if err != io.EOF {
				return nil, err
			}
			return nil, nil
		}
		rr.currentIndex = 0
	}
	row := rr.currentResult.Rows[rr.currentIndex]
	rr.currentIndex++
	return row, nil
}
1006381
func (iter *PermutationIterator) Next() []interface{} {
	if !iter.HasNext() {
		return nil
	}

	if iter.res[0] != nil {
		for i := iter.r - 1; i > -1; i-- {
			iter.cycles[i] -= 1
			if iter.cycles[i] == 0 {
				for x := i; x < iter.n-1; x++ {
					v := iter.indices[x]
					iter.indices[x] = iter.indices[x+1]
					iter.indices[x+1] = v
				}
				iter.cycles[i] = iter.n - i
			} else {
				x := iter.indices[i]
				iter.indices[i] = iter.indices[iter.n-iter.cycles[i]]
				iter.indices[iter.n-iter.cycles[i]] = x
				break
			}
		}
	}

	for i := 0; i < iter.r; i++ {
		iter.res[i] = iter.pool[iter.indices[i]]
	}

	iter.iters += 1

	return iter.res
}
1018860
func (iter *iterator) Next() bool {
	if iter.first {
		iter.first = false
		return iter.n != nil
	}

	if iter.n == nil {
		return false
	}

	iter.n = iter.n.forward[0]
	return iter.n != nil
}
1369806
func (itr *nsIterator) Next() (QueryResult, error) {
	if itr.nextIndex >= itr.lastIndex {
		return nil, nil
	}
	key := itr.sortedKeys[itr.nextIndex]
	vv := itr.nsUpdates.m[key]
	itr.nextIndex++
	return &VersionedKV{CompositeKey{itr.ns, key}, VersionedValue{vv.Value, vv.Metadata, vv.Version}}, nil
}
2478
func (it *Iterator4Chunk) Next() Row {
	if it.cursor >= it.numRows {
		it.cursor = it.numRows + 1
		return it.End()
	}
	row := it.chk.GetRow(int(it.cursor))
	it.cursor++
	return row
}
811895
func (iter *sliceIterator) next() (string, string, int) {
	if iter.position > len(iter.slice)-1 {
		return "", "", -1
	}
	position := iter.position
	iter.position++
	return iter.slice[position], strings.Trim(iter.slice[position], " \t"), position
}
758732
func (iter *ProductIterator) Next() []interface{} {
	if !iter.HasNext() {
		return nil
	}

	if iter.res[0] == nil {
		for i := range iter.res {
			iter.res[i] = iter.pools[i][0]
		}
	} else {
		for i := iter.n - 1; i >= 0; i-- {
			pool := iter.pools[i]
			iter.indices[i] += 1
			if iter.indices[i] == len(pool) {
				iter.indices[i] = 0
				iter.res[i] = pool[0]
			} else {
				iter.res[i] = pool[iter.indices[i]]
				break
			}
		}
	}

	iter.iters += 1

	return iter.res
}
56187
func (e *UnionExec) Next(ctx context.Context, req *chunk.RecordBatch) error {
	if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
		span1 := span.Tracer().StartSpan("union.Next", opentracing.ChildOf(span.Context()))
		defer span1.Finish()
	}
	if e.runtimeStats != nil {
		start := time.Now()
		defer func() { e.runtimeStats.Record(time.Since(start), req.NumRows()) }()
	}
	req.GrowAndReset(e.maxChunkSize)
	if !e.initialized {
		e.initialize(ctx)
		e.initialized = true
	}
	result, ok := <-e.resultPool
	if !ok {
		return nil
	}
	if result.err != nil {
		return errors.Trace(result.err)
	}

	req.SwapColumns(result.chk)
	result.src <- result.chk
	return nil
}