-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 childrenResult from baseExecutor #7076
Merged
lysu
merged 7 commits into
pingcap:master
from
lysu:dev/remove_childrenResult_from_baseExecutor
Jul 18, 2018
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6930b9
executor: remove childrenResult from baseExecutor
lysu 6de71ff
address comments.
lysu 8f5df7a
address comment
lysu 2bd0b94
address comment
lysu 56e7306
Merge branch 'master' into dev/remove_childrenResult_from_baseExecutor
lysu cb6b356
Merge branch 'master' into dev/remove_childrenResult_from_baseExecutor
lysu ff7ce15
Merge branch 'master' into dev/remove_childrenResult_from_baseExecutor
winoros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,13 +63,12 @@ var ( | |
) | ||
|
||
type baseExecutor struct { | ||
ctx sessionctx.Context | ||
id string | ||
schema *expression.Schema | ||
maxChunkSize int | ||
children []Executor | ||
childrenResults []*chunk.Chunk | ||
retFieldTypes []*types.FieldType | ||
ctx sessionctx.Context | ||
id string | ||
schema *expression.Schema | ||
maxChunkSize int | ||
children []Executor | ||
retFieldTypes []*types.FieldType | ||
} | ||
|
||
// Open initializes children recursively and "childrenResults" according to children's schemas. | ||
|
@@ -80,10 +79,6 @@ func (e *baseExecutor) Open(ctx context.Context) error { | |
return errors.Trace(err) | ||
} | ||
} | ||
e.childrenResults = make([]*chunk.Chunk, 0, len(e.children)) | ||
for _, child := range e.children { | ||
e.childrenResults = append(e.childrenResults, child.newChunk()) | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -95,7 +90,6 @@ func (e *baseExecutor) Close() error { | |
return errors.Trace(err) | ||
} | ||
} | ||
e.childrenResults = nil | ||
return nil | ||
} | ||
|
||
|
@@ -512,6 +506,8 @@ type LimitExec struct { | |
|
||
// meetFirstBatch represents whether we have met the first valid Chunk from child. | ||
meetFirstBatch bool | ||
|
||
childResult *chunk.Chunk | ||
} | ||
|
||
// Next implements the Executor Next interface. | ||
|
@@ -521,11 +517,11 @@ func (e *LimitExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |
return nil | ||
} | ||
for !e.meetFirstBatch { | ||
err := e.children[0].Next(ctx, e.childrenResults[0]) | ||
err := e.children[0].Next(ctx, e.childResult) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
batchSize := uint64(e.childrenResults[0].NumRows()) | ||
batchSize := uint64(e.childResult.NumRows()) | ||
// no more data. | ||
if batchSize == 0 { | ||
return nil | ||
|
@@ -540,7 +536,7 @@ func (e *LimitExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |
if begin == end { | ||
break | ||
} | ||
chk.Append(e.childrenResults[0], int(begin), int(end)) | ||
chk.Append(e.childResult, int(begin), int(end)) | ||
return nil | ||
} | ||
e.cursor += batchSize | ||
|
@@ -567,11 +563,21 @@ func (e *LimitExec) Open(ctx context.Context) error { | |
if err := e.baseExecutor.Open(ctx); err != nil { | ||
return errors.Trace(err) | ||
} | ||
e.childResult = e.children[0].newChunk() | ||
e.cursor = 0 | ||
e.meetFirstBatch = e.begin == 0 | ||
return nil | ||
} | ||
|
||
// Close implements the Executor Close interface. | ||
func (e *LimitExec) Close() error { | ||
e.childResult = nil | ||
if err := errors.Trace(e.baseExecutor.Close()); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
// While doing optimization in the plan package, we need to execute uncorrelated subquery, | ||
// but the plan package cannot import the executor package because of the dependency cycle. | ||
|
@@ -646,32 +652,35 @@ func (e *TableDualExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |
type SelectionExec struct { | ||
baseExecutor | ||
|
||
batched bool | ||
filters []expression.Expression | ||
selected []bool | ||
inputIter *chunk.Iterator4Chunk | ||
inputRow chunk.Row | ||
batched bool | ||
filters []expression.Expression | ||
selected []bool | ||
inputIter *chunk.Iterator4Chunk | ||
inputRow chunk.Row | ||
childResult *chunk.Chunk | ||
} | ||
|
||
// Open implements the Executor Open interface. | ||
func (e *SelectionExec) Open(ctx context.Context) error { | ||
if err := e.baseExecutor.Open(ctx); err != nil { | ||
return errors.Trace(err) | ||
} | ||
e.childResult = e.children[0].newChunk() | ||
e.batched = expression.Vectorizable(e.filters) | ||
if e.batched { | ||
e.selected = make([]bool, 0, chunk.InitialCapacity) | ||
} | ||
e.inputIter = chunk.NewIterator4Chunk(e.childrenResults[0]) | ||
e.inputIter = chunk.NewIterator4Chunk(e.childResult) | ||
e.inputRow = e.inputIter.End() | ||
return nil | ||
} | ||
|
||
// Close implements plan.Plan Close interface. | ||
func (e *SelectionExec) Close() error { | ||
if err := e.baseExecutor.Close(); err != nil { | ||
return errors.Trace(err) | ||
if err := errors.Trace(e.baseExecutor.Close()); err != nil { | ||
return err | ||
} | ||
e.childResult = nil | ||
e.selected = nil | ||
return nil | ||
} | ||
|
@@ -694,12 +703,12 @@ func (e *SelectionExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |
} | ||
chk.AppendRow(e.inputRow) | ||
} | ||
err := e.children[0].Next(ctx, e.childrenResults[0]) | ||
err := e.children[0].Next(ctx, e.childResult) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
// no more data. | ||
if e.childrenResults[0].NumRows() == 0 { | ||
if e.childResult.NumRows() == 0 { | ||
return nil | ||
} | ||
e.selected, err = expression.VectorizedFilter(e.ctx, e.filters, e.inputIter, e.selected) | ||
|
@@ -726,13 +735,13 @@ func (e *SelectionExec) unBatchedNext(ctx context.Context, chk *chunk.Chunk) err | |
return nil | ||
} | ||
} | ||
err := e.children[0].Next(ctx, e.childrenResults[0]) | ||
err := e.children[0].Next(ctx, e.childResult) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
e.inputRow = e.inputIter.Begin() | ||
// no more data. | ||
if e.childrenResults[0].NumRows() == 0 { | ||
if e.childResult.NumRows() == 0 { | ||
return nil | ||
} | ||
} | ||
|
@@ -838,14 +847,16 @@ func (e *TableScanExec) Open(ctx context.Context) error { | |
type ExistsExec struct { | ||
baseExecutor | ||
|
||
evaluated bool | ||
evaluated bool | ||
childResult *chunk.Chunk | ||
} | ||
|
||
// Open implements the Executor Open interface. | ||
func (e *ExistsExec) Open(ctx context.Context) error { | ||
if err := e.baseExecutor.Open(ctx); err != nil { | ||
return errors.Trace(err) | ||
} | ||
e.childResult = e.children[0].newChunk() | ||
e.evaluated = false | ||
return nil | ||
} | ||
|
@@ -855,11 +866,11 @@ func (e *ExistsExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |
chk.Reset() | ||
if !e.evaluated { | ||
e.evaluated = true | ||
err := e.children[0].Next(ctx, e.childrenResults[0]) | ||
err := e.children[0].Next(ctx, e.childResult) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
if e.childrenResults[0].NumRows() > 0 { | ||
if e.childResult.NumRows() > 0 { | ||
chk.AppendInt64(0, 1) | ||
} else { | ||
chk.AppendInt64(0, 0) | ||
|
@@ -868,6 +879,15 @@ func (e *ExistsExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |
return nil | ||
} | ||
|
||
// Close implements the Executor Close interface. | ||
func (e *ExistsExec) Close() error { | ||
e.childResult = nil | ||
if err := errors.Trace(e.baseExecutor.Close()); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// MaxOneRowExec checks if the number of rows that a query returns is at maximum one. | ||
// It's built from subquery expression. | ||
type MaxOneRowExec struct { | ||
|
@@ -937,6 +957,8 @@ type UnionExec struct { | |
resourcePools []chan *chunk.Chunk | ||
resultPool chan *unionWorkerResult | ||
initialized bool | ||
|
||
childrenResults []*chunk.Chunk | ||
} | ||
|
||
// unionWorkerResult stores the result for a union worker. | ||
|
@@ -959,6 +981,9 @@ func (e *UnionExec) Open(ctx context.Context) error { | |
if err := e.baseExecutor.Open(ctx); err != nil { | ||
return errors.Trace(err) | ||
} | ||
for _, child := range e.children { | ||
e.childrenResults = append(e.childrenResults, child.newChunk()) | ||
} | ||
e.stopFetchData.Store(false) | ||
e.initialized = false | ||
e.finished = make(chan struct{}) | ||
|
@@ -1039,6 +1064,7 @@ func (e *UnionExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |
// Close implements the Executor Close interface. | ||
func (e *UnionExec) Close() error { | ||
close(e.finished) | ||
e.childrenResults = nil | ||
if e.resultPool != nil { | ||
for range e.resultPool { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just return it. It's ok not to have this if branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I mean in the previous comments.😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 😂😂