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 index_look_up_merge_join to speed up index_look_up_join #9571

Closed
Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d209485
ci
lzmhhh123 Nov 21, 2018
abb1dd0
initialization
lzmhhh123 Mar 4, 2019
8f20e84
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 Mar 4, 2019
280ebc7
finish core
lzmhhh123 Mar 5, 2019
ac24f82
add comments
lzmhhh123 Mar 5, 2019
ec91f35
debug
lzmhhh123 Mar 6, 2019
0dadc5e
improve
lzmhhh123 Mar 7, 2019
9db06f6
debug
lzmhhh123 Mar 7, 2019
551ff53
debug
lzmhhh123 Mar 7, 2019
b9d6415
debug
lzmhhh123 Mar 8, 2019
b00365c
debug
lzmhhh123 Mar 8, 2019
da586ee
debug
lzmhhh123 Mar 8, 2019
925df37
debug
lzmhhh123 Mar 8, 2019
70a6790
Merge branch 'master' into dev/index_look_up_merge_join
zhouqiang-cl Mar 9, 2019
9d9015e
change merge worker into inner worker
lzmhhh123 Mar 11, 2019
12f1d31
Merge branch 'dev/index_look_up_merge_join' of https://github.com/lzm…
lzmhhh123 Mar 11, 2019
531a028
make results to chan
lzmhhh123 Mar 11, 2019
06320c8
debug
lzmhhh123 Mar 11, 2019
8063340
improve
lzmhhh123 Mar 11, 2019
f53e06e
reduce chan size
lzmhhh123 Mar 12, 2019
1781313
debug
lzmhhh123 Mar 12, 2019
f381771
improve
lzmhhh123 Mar 12, 2019
75d75c0
improve
lzmhhh123 Mar 12, 2019
e2f0936
improve
lzmhhh123 Mar 12, 2019
d5f8362
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 Mar 12, 2019
8570b39
debug
lzmhhh123 Mar 12, 2019
c999301
change log & add indexLookUpReader
lzmhhh123 Mar 13, 2019
81217b7
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 Mar 14, 2019
fcfe117
improve
lzmhhh123 Mar 15, 2019
de68d11
debug
lzmhhh123 Mar 18, 2019
3ab3753
test change
lzmhhh123 Mar 18, 2019
23e62fc
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 Mar 18, 2019
917e46f
change test
lzmhhh123 Mar 18, 2019
ee838db
debug
lzmhhh123 Mar 18, 2019
8e1bd95
add prop items
lzmhhh123 Mar 18, 2019
98a390f
change
lzmhhh123 Mar 18, 2019
c651d64
address comments
lzmhhh123 Mar 19, 2019
3f38f2e
ci
lzmhhh123 Mar 19, 2019
0556a46
ci
lzmhhh123 Mar 19, 2019
bea33cd
remove unnecessary judgement
lzmhhh123 Mar 19, 2019
a5acaf5
remove context import from golang/x
lzmhhh123 Mar 19, 2019
5fdd79c
change
lzmhhh123 Mar 20, 2019
f4e9fc8
split joiner
lzmhhh123 Mar 21, 2019
b4b222f
debug
lzmhhh123 Mar 21, 2019
b74396d
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 Jul 2, 2019
6c3888b
plug-in index join enhance code
lzmhhh123 Jul 2, 2019
1aaf860
adapt bug fix #10244
lzmhhh123 Jul 2, 2019
b29e4ec
fix bug
lzmhhh123 Jul 2, 2019
56d45f8
add outerjoin required size control
lzmhhh123 Jul 3, 2019
eb55d55
address comments
lzmhhh123 Jul 11, 2019
a4b4d08
fix ci
lzmhhh123 Jul 12, 2019
4ad2c89
fix explain test
lzmhhh123 Jul 15, 2019
97c88e3
Merge branch 'master' into dev/index_look_up_merge_join
lzmhhh123 Jul 15, 2019
4a2156b
fix index pre_length bug in indexjoin
lzmhhh123 Jul 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 68 additions & 11 deletions executor/builder.go
Expand Up @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would outerKeyColIdx be clearer?

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about innerPlan.(*plannercore.PhysicalTableReader) && IndexPlans[0].(*PhysicalTableScan) is true?

Copy link
Member Author

Choose a reason for hiding this comment

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

If code like this? How to get the IndexScan?

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
}

Expand Down