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, expression: add a tryToMatchOuters for joiner #11922

Merged
merged 12 commits into from
Sep 10, 2019

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Aug 29, 2019

What problem does this PR solve?

Add a tryToMatchOuters interface in joiner which joins a batch out outer rows and one inner row every time.

What is changed and how it works?

Check List

Tests

Exist tests.
More test case needs to be added.

Code changes

  • Has exported function/method change
  • Has exported variable/fields change

Side effects

N/A

Related changes

N/A

Release note

N/A

@XuHuaiyu XuHuaiyu added type/enhancement The issue or PR belongs to an enhancement. status/WIP sig/execution SIG execution labels Aug 29, 2019
@codecov
Copy link

codecov bot commented Aug 29, 2019

Codecov Report

Merging #11922 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11922   +/-   ##
===========================================
  Coverage   81.5083%   81.5083%           
===========================================
  Files           449        449           
  Lines         97390      97390           
===========================================
  Hits          79381      79381           
  Misses        12385      12385           
  Partials       5624       5624

@XuHuaiyu XuHuaiyu mentioned this pull request Sep 3, 2019
@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Sep 4, 2019

/run-all-tests

executor/joiner.go Outdated Show resolved Hide resolved
executor/joiner.go Outdated Show resolved Hide resolved
executor/joiner.go Outdated Show resolved Hide resolved
executor/index_lookup_hash_join.go Outdated Show resolved Hide resolved
executor/index_lookup_hash_join.go Show resolved Hide resolved
executor/index_lookup_hash_join.go Outdated Show resolved Hide resolved
executor/joiner.go Outdated Show resolved Hide resolved
executor/joiner.go Show resolved Hide resolved
executor/joiner.go Outdated Show resolved Hide resolved
Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

LGTM

@SunRunAway SunRunAway added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 5, 2019
executor/index_lookup_hash_join.go Show resolved Hide resolved
}
outerRowStatus = append(outerRowStatus, outerRowMatched)
if matched {
chk.AppendPartialRow(0, outer)
Copy link
Member

Choose a reason for hiding this comment

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

Should we only decrease numToAppend when this operation is performed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No~ outers.Next is needed.

}
return outerRowStatus, nil
}
for outer, i := outers.Current(), 0; outer != outers.End() && numToAppend > 0; outer, numToAppend, i = outers.Next(), numToAppend-1, i+1 {
Copy link
Member

Choose a reason for hiding this comment

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

i is unused.

return outerRowStatus, nil
}

for i := 0; outer != outers.End() && numToAppend > 0; outer, numToAppend, i = outers.Next(), numToAppend-1, i+1 {
Copy link
Member

Choose a reason for hiding this comment

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

i is unused

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Sep 9, 2019

PTAL @zz-jason

@XuHuaiyu
Copy link
Contributor Author

PTAL @zz-jason @qw4990 @fzhedu

Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

@qw4990 qw4990 added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 10, 2019
task.outerRowStatus[rowIdx] = outerRowHasNull
for _, status := range iw.outerRowStatus {
outerRowIdx := matchedOuterRowIdx[cursor]
if status == outerRowMatched || task.outerRowStatus[outerRowIdx] == outerRowUnmatched {
Copy link
Member

Choose a reason for hiding this comment

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

can it be replaced with the following condition?

if task.outerRowStatus[outerRowIdx] == outerRowUnMatched {
    task.outerRowStatus[outerRowIdx] = status
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No
If so, when task.outerRowStatus[outerRowIdx] == outerRowHasNull && status == outerRowMatched is true, it will cause error.

// returns two bool slices, `selected` indicates whether a row passed the
// filters, `isNull` indicates whether the result of the filter is null.
// Filters is executed vectorized.
func VectorizedFilterConsiderNull(ctx sessionctx.Context, filters []Expression, iterator *chunk.Iterator4Chunk, selected []bool, isNil []bool) ([]bool, []bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

  1. s/isNil/isNull/
  2. Can we refactor VectorizedFilter() to call VectorizedFilterConsiderNull()?

// tryToMatchOuters, the result is built by multiple outer rows and one inner
// row. The returned outerRowStatusFlag slice value indicates the status of
// each outer row (matched/unmatched/hasNull).
func (j *baseJoiner) filterAndCheckOuterRowStatus(input, output *chunk.Chunk, innerColsLen int, outerRowStatus []outerRowStatusFlag) (_ []outerRowStatusFlag, _ error) {
Copy link
Member

Choose a reason for hiding this comment

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

can we refactor it to call j.Filter() then update outerRowStatus?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code already did this?

}

outer, numToAppend, outerBatchSize := outers.Current(), chk.RequiredRows()-chk.NumRows(), 0
for ; outer != outers.End() && numToAppend > 0; outer, numToAppend, outerBatchSize = outers.Next(), numToAppend-1, outerBatchSize+1 {
Copy link
Member

Choose a reason for hiding this comment

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

Don't need to calculate outerBatchSize in every loop. We can calculate it when the loop is finished:

outer, numToAppend := outers.Current(), chk.RequiredRows()-chk.NumRows()
for ; outer != outers.End() && numToAppend > 0; outer, numToAppend = outers.Next(), numToAppend-1 {
    j.makeJoinRowToChunk(chkForJoin, outer, inner)
}

outerBatchSize := chk.RequiredRows() - chk.NumRows() - numToAppend
// do something

BTW, the for loop looks a little complicated, we can simplify it to:

for outer != outers.End() && numToAppend > 0 {
    j.makeJoinRowToChunk(chkForJoin, outer, inner)
    outer = outers.Next()
    numToAppend = numToAppend - 1
}

@sre-bot
Copy link
Contributor

sre-bot commented Sep 10, 2019

/run-all-tests

@sre-bot sre-bot merged commit d5626a9 into pingcap:master Sep 10, 2019
@XuHuaiyu
Copy link
Contributor Author

@zz-jason This commit is merged...
I'll handle the comments with the following PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants