-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
planner: generate IndexMergePath in physical optimization #10512
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d8df7b1
Add some parameters in accessPath to record IndexMergePath infos;
b5b77f5
update copyright
e3c74a5
fix ci
290011c
remove debug info
9bd3e62
add comment and fix make
1eb4140
fix some format
0f9a9dd
rename some functions and change some implements
5d3a8e2
change some implement details
4a37fe7
fix ci
e706a7f
add break
52c66bf
ix->idx
1cb2897
usedIndexCount->len
3cdf74f
add primary key check
3db2587
fix some bugs
b97b719
temp
0d03546
re-implement the pk path
ecd4f46
fix ci
caf1cf4
add debug and consider noIntervalRanges
a1b79e5
fix ci
afa3790
add unique check for index path
a8b5b85
fix comments, and debug info
b10e31a
add assign EnableIndexMerge in NewSessionVars()
09837be
fix some typos and ix->idx
09f1ae3
Merge branch 'master' into IndexMergeDev
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 |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package core | ||
|
||
import ( | ||
. "github.com/pingcap/check" | ||
"github.com/pingcap/parser" | ||
"github.com/pingcap/parser/ast" | ||
"github.com/pingcap/parser/model" | ||
"github.com/pingcap/tidb/infoschema" | ||
"github.com/pingcap/tidb/sessionctx" | ||
"github.com/pingcap/tidb/util/testleak" | ||
) | ||
|
||
var _ = Suite(&testIndexMergeSuite{}) | ||
|
||
type testIndexMergeSuite struct { | ||
*parser.Parser | ||
|
||
is infoschema.InfoSchema | ||
ctx sessionctx.Context | ||
} | ||
|
||
func (s *testIndexMergeSuite) SetUpSuite(c *C) { | ||
s.is = infoschema.MockInfoSchema([]*model.TableInfo{MockTable(), MockView()}) | ||
s.ctx = MockContext() | ||
s.Parser = parser.New() | ||
} | ||
|
||
func getIndexMergePathDigest(paths []*accessPath, startIndex int) string { | ||
if len(paths) == startIndex { | ||
return "[]" | ||
} | ||
idxMergeDisgest := "[" | ||
for i := startIndex; i < len(paths); i++ { | ||
if i != startIndex { | ||
idxMergeDisgest += "," | ||
} | ||
path := paths[i] | ||
idxMergeDisgest += "{Idxs:[" | ||
for j := 0; j < len(path.partialIndexPaths); j++ { | ||
if j > 0 { | ||
idxMergeDisgest += "," | ||
} | ||
idxMergeDisgest += path.partialIndexPaths[j].index.Name.L | ||
} | ||
idxMergeDisgest += "],TbFilters:[" | ||
for j := 0; j < len(path.tableFilters); j++ { | ||
if j > 0 { | ||
idxMergeDisgest += "," | ||
} | ||
idxMergeDisgest += path.tableFilters[j].String() | ||
} | ||
idxMergeDisgest += "]}" | ||
} | ||
idxMergeDisgest += "]" | ||
return idxMergeDisgest | ||
} | ||
|
||
func (s *testIndexMergeSuite) TestIndexMergePathGenerateion(c *C) { | ||
defer testleak.AfterTest(c)() | ||
tests := []struct { | ||
sql string | ||
idxMergeDigest string | ||
}{ | ||
{ | ||
sql: "select * from t", | ||
idxMergeDigest: "[]", | ||
}, | ||
{ | ||
sql: "select * from t where c < 1", | ||
idxMergeDigest: "[]", | ||
}, | ||
{ | ||
sql: "select * from t where c < 1 or f > 2", | ||
idxMergeDigest: "[{Idxs:[c_d_e,f_g],TbFilters:[]}]", | ||
}, | ||
{ | ||
sql: "select * from t where (c < 1 or f > 2) and (c > 5 or f < 7)", | ||
idxMergeDigest: "[{Idxs:[c_d_e,f_g],TbFilters:[or(gt(test.t.c, 5), lt(test.t.f, 7))]}," + | ||
"{Idxs:[c_d_e,f_g],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2))]}]", | ||
}, | ||
{ | ||
sql: "select * from t where (c < 1 or f > 2) and (c > 5 or f < 7) and (c < 1 or g > 2)", | ||
idxMergeDigest: "[{Idxs:[c_d_e,f_g],TbFilters:[or(gt(test.t.c, 5), lt(test.t.f, 7)),or(lt(test.t.c, 1), gt(test.t.g, 2))]}," + | ||
"{Idxs:[c_d_e,f_g],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2)),or(lt(test.t.c, 1), gt(test.t.g, 2))]}," + | ||
"{Idxs:[c_d_e,g],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2)),or(gt(test.t.c, 5), lt(test.t.f, 7))]}]", | ||
}, | ||
{ | ||
sql: "select * from t where (c < 1 or f > 2) and (c > 5 or f < 7) and (e < 1 or f > 2)", | ||
idxMergeDigest: "[{Idxs:[c_d_e,f_g],TbFilters:[or(gt(test.t.c, 5), lt(test.t.f, 7)),or(lt(test.t.e, 1), gt(test.t.f, 2))]}," + | ||
"{Idxs:[c_d_e,f_g],TbFilters:[or(lt(test.t.c, 1), gt(test.t.f, 2)),or(lt(test.t.e, 1), gt(test.t.f, 2))]}]", | ||
}, | ||
} | ||
for i, tc := range tests { | ||
comment := Commentf("case:%v sql:%s", i, tc.sql) | ||
stmt, err := s.ParseOneStmt(tc.sql, "", "") | ||
c.Assert(err, IsNil, comment) | ||
Preprocess(s.ctx, stmt, s.is) | ||
builder := &PlanBuilder{ | ||
ctx: MockContext(), | ||
is: s.is, | ||
colMapper: make(map[*ast.ColumnNameExpr]int), | ||
} | ||
p, err := builder.Build(stmt) | ||
if err != nil { | ||
c.Assert(err.Error(), Equals, tc.idxMergeDigest, comment) | ||
continue | ||
} | ||
c.Assert(err, IsNil) | ||
p, err = logicalOptimize(builder.optFlag, p.(LogicalPlan)) | ||
c.Assert(err, IsNil) | ||
lp := p.(LogicalPlan) | ||
c.Assert(err, IsNil) | ||
var ds *DataSource | ||
for ds == nil { | ||
switch v := lp.(type) { | ||
case *DataSource: | ||
ds = v | ||
default: | ||
lp = lp.Children()[0] | ||
} | ||
} | ||
ds.ctx.GetSessionVars().EnableIndexMerge = true | ||
idxMergeStartIndex := len(ds.possibleAccessPaths) | ||
_, err = lp.recursiveDeriveStats() | ||
c.Assert(err, IsNil) | ||
c.Assert(getIndexMergePathDigest(ds.possibleAccessPaths, idxMergeStartIndex), Equals, tc.idxMergeDigest) | ||
} | ||
} |
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
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.
I hope that you can do cleanup here. (Of course, no need to do it in this pr)
Split the struct
accessPath
toaccessPath
andsingleIndexPath
/or some other name would be better.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.
ok, I will consider it later.