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

planner: check full match of each range for BatchPointGet plan (#19456) #19460

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,14 @@ func (ds *DataSource) canConvertToPointGet(candidate *candidatePath) bool {
canConvertPointGet = canConvertPointGet && candidate.path.StoreType != kv.TiFlash
if !candidate.path.IsTablePath {
canConvertPointGet = canConvertPointGet &&
candidate.path.Index.Unique &&
!candidate.path.Index.HasPrefixIndex() &&
len(candidate.path.Ranges[0].LowVal) == len(candidate.path.Index.Columns)
candidate.path.Index.Unique && !candidate.path.Index.HasPrefixIndex()
idxColsLen := len(candidate.path.Index.Columns)
for _, ran := range candidate.path.Ranges {
if len(ran.LowVal) != idxColsLen {
canConvertPointGet = false
break
}
}
}
if !canConvertPointGet {
return false
Expand Down
14 changes: 14 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,17 @@ func (s *testIntegrationSerialSuite) TestExplainAnalyzePointGet(c *C) {
res = tk.MustQuery("explain analyze select * from t where a in (1,2,3);")
checkExplain("BatchGet")
}

func (s *testIntegrationSuite) TestPartialBatchPointGet(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (c_int int, c_str varchar(40), primary key(c_int, c_str))")
tk.MustExec("insert into t values (3, 'bose')")
tk.MustQuery("select * from t where c_int in (3)").Check(testkit.Rows(
"3 bose",
))
tk.MustQuery("select * from t where c_int in (3) or c_str in ('yalow') and c_int in (1, 2)").Check(testkit.Rows(
"3 bose",
))
}