Skip to content

Commit

Permalink
address reviewer's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
zhexuany committed Jul 17, 2018
1 parent f0169aa commit 333fd30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
13 changes: 13 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,19 @@ func (b *executorBuilder) buildDDL(v *plan.DDL) Executor {
return e
}

// buildExplain builds a explain executor. `e.rows` collects final result and
// displays it in sql-shell.
func (b *executorBuilder) buildExplain(v *plan.Explain) Executor {
e := &ExplainExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
}
e.rows = make([][]string, 0, len(v.Rows))
for _, row := range v.Rows {
e.rows = append(e.rows, row)
}
return e
}

func (b *executorBuilder) buildUnionScanExec(v *plan.PhysicalUnionScan) Executor {
src := b.build(v.Children()[0])
if b.err != nil {
Expand Down
14 changes: 0 additions & 14 deletions executor/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package executor

import (
"github.com/cznic/mathutil"
"github.com/pingcap/tidb/plan"
"github.com/pingcap/tidb/util/chunk"
"golang.org/x/net/context"
)
Expand All @@ -28,19 +27,6 @@ type ExplainExec struct {
cursor int
}

// buildExplain builds a explain executor. `e.rows` collects final result and
// displays it in sql-shell.
func (b *executorBuilder) buildExplain(v *plan.Explain) Executor {
e := &ExplainExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
}
e.rows = make([][]string, 0, len(v.Rows))
for _, row := range v.Rows {
e.rows = append(e.rows, row)
}
return e
}

// Close implements the Executor Close interface.
func (e *ExplainExec) Close() error {
e.rows = nil
Expand Down
36 changes: 18 additions & 18 deletions executor/table_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"golang.org/x/net/context"
)

// TableReaderExecutor sends dag request and reads table data from kv layer.
// TableReaderExecutor sends DAG request and reads table data from kv layer.
type TableReaderExecutor struct {
baseExecutor

Expand All @@ -52,23 +52,6 @@ type TableReaderExecutor struct {
plans []plan.PhysicalPlan
}

// Close implements the Executor Close interface.
func (e *TableReaderExecutor) Close() error {
e.ctx.StoreQueryFeedback(e.feedback)
err := e.resultHandler.Close()
return errors.Trace(err)
}

// Next fills data into the chunk passed by its caller.
// The task was actually done by tableReaderHandler.
func (e *TableReaderExecutor) Next(ctx context.Context, chk *chunk.Chunk) error {
err := e.resultHandler.nextChunk(ctx, chk)
if err != nil {
e.feedback.Invalidate()
}
return errors.Trace(err)
}

// Open initialzes necessary variables for using this executor.
func (e *TableReaderExecutor) Open(ctx context.Context) error {
span, ctx := startSpanFollowsContext(ctx, "executor.TableReader.Open")
Expand Down Expand Up @@ -112,6 +95,23 @@ func (e *TableReaderExecutor) Open(ctx context.Context) error {
return nil
}

// Next fills data into the chunk passed by its caller.
// The task was actually done by tableReaderHandler.
func (e *TableReaderExecutor) Next(ctx context.Context, chk *chunk.Chunk) error {
err := e.resultHandler.nextChunk(ctx, chk)
if err != nil {
e.feedback.Invalidate()
}
return errors.Trace(err)
}

// Close implements the Executor Close interface.
func (e *TableReaderExecutor) Close() error {
e.ctx.StoreQueryFeedback(e.feedback)
err := e.resultHandler.Close()
return errors.Trace(err)
}

// buildResp first build request and send it to tikv using distsql.Select. It uses SelectResut returned by the callee
// to fetch all results.
func (e *TableReaderExecutor) buildResp(ctx context.Context, ranges []*ranger.Range) (distsql.SelectResult, error) {
Expand Down

0 comments on commit 333fd30

Please sign in to comment.