-
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 2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,8 @@ type HashAggExec struct { | |
defaultVal *chunk.Chunk | ||
// isChildReturnEmpty indicates whether the child executor only returns an empty input. | ||
isChildReturnEmpty bool | ||
|
||
childResult *chunk.Chunk | ||
} | ||
|
||
// HashAggInput indicates the input of hash agg exec. | ||
|
@@ -201,6 +203,7 @@ func (d *HashAggIntermData) ToRows(sc *stmtctx.StatementContext, rows []types.Da | |
// Close implements the Executor Close interface. | ||
func (e *HashAggExec) Close() error { | ||
if e.isUnparallelExec { | ||
e.childResult = nil | ||
e.groupMap = nil | ||
e.groupIterator = nil | ||
e.aggCtxsMap = nil | ||
|
@@ -247,6 +250,7 @@ func (e *HashAggExec) initForUnparallelExec() { | |
e.rowBuffer = make([]types.Datum, 0, e.Schema().Len()) | ||
e.groupKey = make([]byte, 0, 8) | ||
e.groupVals = make([][]byte, 0, 8) | ||
e.childResult = e.children[0].newChunk() | ||
} | ||
|
||
func (e *HashAggExec) initForParallelExec() { | ||
|
@@ -676,14 +680,14 @@ func (e *HashAggExec) unparallelExec(ctx context.Context, chk *chunk.Chunk) erro | |
|
||
// execute fetches Chunks from src and update each aggregate function for each row in Chunk. | ||
func (e *HashAggExec) execute(ctx context.Context) (err error) { | ||
inputIter := chunk.NewIterator4Chunk(e.childrenResults[0]) | ||
inputIter := chunk.NewIterator4Chunk(e.childResult) | ||
for { | ||
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 | ||
} | ||
for row := inputIter.Begin(); row != inputIter.End(); row = inputIter.Next() { | ||
|
@@ -765,17 +769,19 @@ type StreamAggExec struct { | |
newAggFuncs []aggfuncs.AggFunc | ||
partialResults []aggfuncs.PartialResult | ||
groupRows []chunk.Row | ||
|
||
childResult *chunk.Chunk | ||
} | ||
|
||
// Open implements the Executor Open interface. | ||
func (e *StreamAggExec) Open(ctx context.Context) error { | ||
if err := e.baseExecutor.Open(ctx); err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
e.childResult = e.children[0].newChunk() | ||
e.executed = false | ||
e.isChildReturnEmpty = true | ||
e.inputIter = chunk.NewIterator4Chunk(e.childrenResults[0]) | ||
e.inputIter = chunk.NewIterator4Chunk(e.childResult) | ||
e.inputRow = e.inputIter.End() | ||
e.mutableRow = chunk.MutRowFromTypes(e.retTypes()) | ||
e.rowBuffer = make([]types.Datum, 0, e.Schema().Len()) | ||
|
@@ -795,6 +801,15 @@ func (e *StreamAggExec) Open(ctx context.Context) error { | |
return nil | ||
} | ||
|
||
// Close implements the Executor Close interface. | ||
func (e *StreamAggExec) Close() error { | ||
e.childResult = nil | ||
if err := 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. return errors.Trace(e.baseExecutor.Close()) // I prefer this. or err := e.baseExecutor.Close()
return errors.Trace(err) |
||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Next implements the Executor Next interface. | ||
func (e *StreamAggExec) Next(ctx context.Context, chk *chunk.Chunk) error { | ||
chk.Reset() | ||
|
@@ -876,13 +891,13 @@ func (e *StreamAggExec) fetchChildIfNecessary(ctx context.Context, chk *chunk.Ch | |
} | ||
} | ||
|
||
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 { | ||
if !e.isChildReturnEmpty { | ||
err = e.appendResult2Chunk(chk) | ||
} else if e.defaultVal != nil { | ||
|
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
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.
We could firstly release the resources handled by itself, then release the resources handled by its children.