From 7fe82647ae8daa924bfc99b3e648c7c30fe89afa Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Wed, 26 Aug 2020 20:48:52 +0800 Subject: [PATCH] planner: check full match of each range for BatchPointGet plan (#19456) (#19460) Signed-off-by: ti-srebot --- planner/core/find_best_task.go | 11 ++++++++--- planner/core/integration_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index a7fa84cb76eb6..b578e92d3a70f 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -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 diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index dbc83562db188..359b4b56ce63f 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -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", + )) +}