Skip to content

Commit

Permalink
planner: check full match of each range for BatchPointGet plan (#19456)…
Browse files Browse the repository at this point in the history
… (#19460)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Aug 26, 2020
1 parent 397fce9 commit 7fe8264
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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",
))
}

0 comments on commit 7fe8264

Please sign in to comment.