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: support Chunk for UnionExec #5229

Merged
merged 19 commits into from Dec 5, 2017

Conversation

zz-jason
Copy link
Member

@zz-jason zz-jason commented Nov 27, 2017

  1. support NextChunk for UnionExec
  2. for children of union, add projection to do type conversion if necessary.

e.initialize(nil, false)
e.initialized = true
}
result, closed := <-e.resultPool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second returned value is ok, not closed.

@zz-jason zz-jason mentioned this pull request Nov 29, 2017
41 tasks
wg sync.WaitGroup

// For chunk execution.
resoucePool chan *executorResult
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resouce -> resource

return
}
resource := <-e.resoucePool
resource.err = errors.Trace(e.children[childID].NextChunk(resource.chk))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider type conversion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we should


chk.SwapColumns(result.chk)
result.reset()
e.resoucePool <- result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resource pool may be closed by waitAllFinished.

How about just use a mutex protected slice for chunk reuse?

func (e *UnionExec) waitAllFinished() {
type executorResult struct {
chk *chunk.Chunk
err error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a channel in executorResult to reuse the chunk and remove resourcePool?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about it

@zz-jason zz-jason added the WIP label Nov 30, 2017
@zz-jason zz-jason removed the WIP label Dec 1, 2017
@zz-jason
Copy link
Member Author

zz-jason commented Dec 1, 2017

to #5261

@@ -51,6 +51,25 @@ func NewFieldType(tp byte) *FieldType {
}
}

// Equal checks whether two FieldType objects are equal.
func (ft *FieldType) Equal(other *FieldType) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ Equal/ Equals

u.SetSchema(firstSchema)

for childID, child := range u.children {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract this loop as a member function.

}

type execResult struct {
rows []Row
err error
}

type executorResult struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments for executorResult and execResult,
it's really similar.

wg sync.WaitGroup

// For chunk execution.
resourcePool chan *executorResult
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments for resourcePool and resultPool

}
resource := <-e.resourcePool
resource.err = errors.Trace(e.children[childID].NextChunk(resource.chk))
if resource.err != nil || resource.chk.NumRows() == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not need nested loop.

return errors.Trace(err)
}

func (e *UnionExec) resultPuller(childID int) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to add a comment for the execution flow of this func.

@@ -92,6 +92,11 @@ func (c *Chunk) addColumnByFieldType(fieldTp *types.FieldType, initCap int) {
}
}

// SwapColumns swap columns with another Chunk.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ swap/ swaps

if resource.err != nil {
e.stopFetchData.Store(true)
select {
case _, ok := <-e.finished:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to check ok, it's always false, just return.

}
case e.resultPool <- result:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just send without select, the resultPool has enough capacity, it never blocks the sender.

@coocood
Copy link
Member

coocood commented Dec 5, 2017

/run-all-tests

@coocood
Copy link
Member

coocood commented Dec 5, 2017

LGTM

@zz-jason
Copy link
Member Author

zz-jason commented Dec 5, 2017

/run-mybatis-test
/run-sqllogic-test

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason merged commit 5155361 into pingcap:master Dec 5, 2017
@zz-jason zz-jason deleted the dev/chunk/union branch December 5, 2017 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants