Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: remove Next function of IndexReaderExecutor #6165

Merged
merged 10 commits into from
Mar 30, 2018
48 changes: 2 additions & 46 deletions executor/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ type IndexReaderExecutor struct {
dagPB *tipb.DAGRequest

// result returns one or more distsql.PartialResult and each PartialResult is returned by one region.
result distsql.SelectResult
partialResult distsql.PartialResult
result distsql.SelectResult
// columns are only required by union scan.
columns []*model.ColumnInfo
priority int
Expand All @@ -367,54 +366,11 @@ type IndexReaderExecutor struct {
// Close clears all resources hold by current object.
func (e *IndexReaderExecutor) Close() error {
e.ctx.StoreQueryFeedback(e.feedback)
err := closeAll(e.result, e.partialResult)
err := e.result.Close()
e.result = nil
e.partialResult = nil
return errors.Trace(err)
}

// Next returns next available Row. In its process, any error will be returned.
// It first try to fetch a partial result if current partial result is nil.
// If any error appears during this stage, it simply return a error to its caller.
// If it successfully initialize its partial result, it will use this to get next
// available row.
func (e *IndexReaderExecutor) Next(ctx context.Context) (Row, error) {
for {
// Get partial result.
if e.partialResult == nil {
var err error
e.partialResult, err = e.result.Next(ctx)
if err != nil {
e.feedback.Invalidate()
return nil, errors.Trace(err)
}
if e.partialResult == nil {
// Finished.
return nil, nil
}
}
// Get a row from partial result.
rowData, err := e.partialResult.Next(ctx)
if err != nil {
e.feedback.Invalidate()
return nil, errors.Trace(err)
}
if rowData == nil {
// Finish the current partial result and get the next one.
err = e.partialResult.Close()
terror.Log(errors.Trace(err))
e.partialResult = nil
continue
}
err = decodeRawValues(rowData, e.schema, e.ctx.GetSessionVars().GetTimeZone())
if err != nil {
e.feedback.Invalidate()
return nil, errors.Trace(err)
}
return rowData, nil
}
}

// NextChunk implements the Executor NextChunk interface.
func (e *IndexReaderExecutor) NextChunk(ctx context.Context, chk *chunk.Chunk) error {
err := e.result.NextChunk(ctx, chk)
Expand Down