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 index_look_up_merge_join to speed up index_look_up_join #9571
Closed
Closed
Changes from 38 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
d209485
ci
lzmhhh123 abb1dd0
initialization
lzmhhh123 8f20e84
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 280ebc7
finish core
lzmhhh123 ac24f82
add comments
lzmhhh123 ec91f35
debug
lzmhhh123 0dadc5e
improve
lzmhhh123 9db06f6
debug
lzmhhh123 551ff53
debug
lzmhhh123 b9d6415
debug
lzmhhh123 b00365c
debug
lzmhhh123 da586ee
debug
lzmhhh123 925df37
debug
lzmhhh123 70a6790
Merge branch 'master' into dev/index_look_up_merge_join
zhouqiang-cl 9d9015e
change merge worker into inner worker
lzmhhh123 12f1d31
Merge branch 'dev/index_look_up_merge_join' of https://github.com/lzm…
lzmhhh123 531a028
make results to chan
lzmhhh123 06320c8
debug
lzmhhh123 8063340
improve
lzmhhh123 f53e06e
reduce chan size
lzmhhh123 1781313
debug
lzmhhh123 f381771
improve
lzmhhh123 75d75c0
improve
lzmhhh123 e2f0936
improve
lzmhhh123 d5f8362
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 8570b39
debug
lzmhhh123 c999301
change log & add indexLookUpReader
lzmhhh123 81217b7
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 fcfe117
improve
lzmhhh123 de68d11
debug
lzmhhh123 3ab3753
test change
lzmhhh123 23e62fc
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 917e46f
change test
lzmhhh123 ee838db
debug
lzmhhh123 8e1bd95
add prop items
lzmhhh123 98a390f
change
lzmhhh123 c651d64
address comments
lzmhhh123 3f38f2e
ci
lzmhhh123 0556a46
ci
lzmhhh123 bea33cd
remove unnecessary judgement
lzmhhh123 a5acaf5
remove context import from golang/x
lzmhhh123 5fdd79c
change
lzmhhh123 f4e9fc8
split joiner
lzmhhh123 b4b222f
debug
lzmhhh123 b74396d
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 6c3888b
plug-in index join enhance code
lzmhhh123 1aaf860
adapt bug fix #10244
lzmhhh123 b29e4ec
fix bug
lzmhhh123 56d45f8
add outerjoin required size control
lzmhhh123 eb55d55
address comments
lzmhhh123 a4b4d08
fix ci
lzmhhh123 4ad2c89
fix explain test
lzmhhh123 97c88e3
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 4a2156b
fix index pre_length bug in indexjoin
lzmhhh123 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 |
---|---|---|
|
@@ -1529,33 +1529,90 @@ func (b *executorBuilder) buildIndexLookUpJoin(v *plannercore.PhysicalIndexJoin) | |
if defaultValues == nil { | ||
defaultValues = make([]types.Datum, len(innerTypes)) | ||
} | ||
outerKeyCols := make([]int, len(v.OuterJoinKeys)) | ||
for i := 0; i < len(v.OuterJoinKeys); i++ { | ||
outerKeyCols[i] = v.OuterJoinKeys[i].Index | ||
} | ||
innerKeyCols := make([]int, len(v.InnerJoinKeys)) | ||
for i := 0; i < len(v.InnerJoinKeys); i++ { | ||
innerKeyCols[i] = v.InnerJoinKeys[i].Index | ||
} | ||
metrics.ExecutorCounter.WithLabelValues("IndexLookUpJoin").Inc() | ||
|
||
// If the inner join keys are the suffix set of the index, then return the IndexLookUpMergeJoin | ||
lzmhhh123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var isIndexScan bool | ||
var is *plannercore.PhysicalIndexScan | ||
if ir, ok := innerPlan.(*plannercore.PhysicalIndexReader); ok { | ||
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. What about 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. If code like this? How to get the |
||
is, isIndexScan = ir.IndexPlans[0].(*plannercore.PhysicalIndexScan) | ||
} | ||
if ilr, ok := innerPlan.(*plannercore.PhysicalIndexLookUpReader); ok { | ||
is, isIndexScan = ilr.IndexPlans[0].(*plannercore.PhysicalIndexScan) | ||
} | ||
if isIndexScan { | ||
lzmhhh123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
idx := is.Index.Columns | ||
isInnerKeysPrefix := true | ||
for i, innerKey := range v.InnerJoinKeys { | ||
if innerKey.ColName != idx[i].Name { | ||
isInnerKeysPrefix = false | ||
break | ||
} | ||
} | ||
if isInnerKeysPrefix { | ||
is.KeepOrder = true | ||
// enforceOuterOrder means the outerJoinKeys must be the prefix of the prop items of PhysicalIndexJoin | ||
enforceOuterOrder := v.KeepOuterOrder && len(v.OuterJoinKeys) < len(v.PropItems) | ||
compareFuncs := make([]expression.CompareFunc, 0, len(v.OuterJoinKeys)) | ||
outerCompareFuncs := make([]expression.CompareFunc, 0, len(v.OuterJoinKeys)) | ||
for i := range v.OuterJoinKeys { | ||
if enforceOuterOrder && v.PropItems[i].Col.ColName != v.OuterJoinKeys[i].ColName { | ||
enforceOuterOrder = false | ||
} | ||
compareFuncs = append(compareFuncs, expression.GetCmpFunction(v.OuterJoinKeys[i], v.InnerJoinKeys[i])) | ||
outerCompareFuncs = append(outerCompareFuncs, expression.GetCmpFunction(v.OuterJoinKeys[i], v.OuterJoinKeys[i])) | ||
} | ||
return &IndexLookUpMergeJoin{ | ||
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID(), outerExec), | ||
outerMergeCtx: outerMergeCtx{ | ||
rowTypes: outerTypes, | ||
filter: outerFilter, | ||
joinKeys: v.OuterJoinKeys, | ||
keyCols: outerKeyCols, | ||
enforceOuterOrder: enforceOuterOrder, | ||
compareFuncs: outerCompareFuncs, | ||
}, | ||
innerMergeCtx: innerMergeCtx{ | ||
readerBuilder: &dataReaderBuilder{innerPlan, b}, | ||
rowTypes: innerTypes, | ||
joinKeys: v.InnerJoinKeys, | ||
keyCols: innerKeyCols, | ||
compareFuncs: compareFuncs, | ||
}, | ||
workerWg: new(sync.WaitGroup), | ||
joiner: newJoiner(b.ctx, v.JoinType, v.OuterIndex == 1, defaultValues, v.OtherConditions, leftTypes, rightTypes), | ||
indexRanges: v.Ranges, | ||
keyOff2IdxOff: v.KeyOff2IdxOff, | ||
} | ||
} | ||
} | ||
e := &IndexLookUpJoin{ | ||
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID(), outerExec), | ||
outerCtx: outerCtx{ | ||
rowTypes: outerTypes, | ||
filter: outerFilter, | ||
keyCols: outerKeyCols, | ||
}, | ||
innerCtx: innerCtx{ | ||
readerBuilder: &dataReaderBuilder{innerPlan, b}, | ||
rowTypes: innerTypes, | ||
keyCols: innerKeyCols, | ||
}, | ||
workerWg: new(sync.WaitGroup), | ||
joiner: newJoiner(b.ctx, v.JoinType, v.OuterIndex == 1, defaultValues, v.OtherConditions, leftTypes, rightTypes), | ||
indexRanges: v.Ranges, | ||
keyOff2IdxOff: v.KeyOff2IdxOff, | ||
} | ||
outerKeyCols := make([]int, len(v.OuterJoinKeys)) | ||
for i := 0; i < len(v.OuterJoinKeys); i++ { | ||
outerKeyCols[i] = v.OuterJoinKeys[i].Index | ||
} | ||
e.outerCtx.keyCols = outerKeyCols | ||
innerKeyCols := make([]int, len(v.InnerJoinKeys)) | ||
for i := 0; i < len(v.InnerJoinKeys); i++ { | ||
innerKeyCols[i] = v.InnerJoinKeys[i].Index | ||
} | ||
e.innerCtx.keyCols = innerKeyCols | ||
e.joinResult = e.newFirstChunk() | ||
metrics.ExecutorCounter.WithLabelValues("IndexLookUpJoin").Inc() | ||
|
||
return e | ||
lzmhhh123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
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.
Would outerKeyColIdx be clearer?