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
Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
  • Loading branch information
eurekaka and ti-srebot authored Aug 26, 2020
1 parent d434365 commit ef51ea8
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 @@ -675,9 +675,14 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter
canConvertPointGet = canConvertPointGet && candidate.path.StoreType != kv.TiFlash
if !candidate.path.IsIntHandlePath {
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 ds.table.Meta().GetPartitionInfo() != nil && !tryOldPartitionImplementation(ds.ctx) {
canConvertPointGet = 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 @@ -1519,3 +1519,17 @@ partition p2 values less than (10))`)
tk.MustQuery("explain " + tt).Check(testkit.Rows(output[i].Plan...))
}
}

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 ef51ea8

Please sign in to comment.