From fb952937dcef74555af9b3333801a0628e61565f Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Fri, 21 Aug 2020 15:21:27 +0800 Subject: [PATCH] planner: make single partition table support index join on inner side (#19151) (#19197) Signed-off-by: ti-srebot --- executor/index_lookup_merge_join_test.go | 24 ++++++++++++++++++++++++ planner/core/exhaust_physical_plans.go | 2 ++ 2 files changed, 26 insertions(+) diff --git a/executor/index_lookup_merge_join_test.go b/executor/index_lookup_merge_join_test.go index 3534a2fdc26e8..d979e60c0c44d 100644 --- a/executor/index_lookup_merge_join_test.go +++ b/executor/index_lookup_merge_join_test.go @@ -64,3 +64,27 @@ func (s *testSuite9) TestIssue18631(c *C) { "2 2 2 2 2 2 2 2", "1 1 1 1 1 1 1 1")) } + +func (s *testSuiteAgg) TestIndexJoinOnSinglePartitionTable(c *C) { + // For issue 19145 + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("drop table if exists t1, t2") + tk.MustExec("create table t1 (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue )") + tk.MustExec("create table t2 (c_int int, c_str varchar(40), primary key (c_int) ) partition by range (c_int) ( partition p0 values less than (10), partition p1 values less than maxvalue )") + tk.MustExec("insert into t1 values (1, 'Alice')") + tk.MustExec("insert into t2 values (1, 'Bob')") + sql := "select /*+ INL_MERGE_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str" + tk.MustQuery(sql).Check(testkit.Rows("1 Alice 1 Bob")) + rows := s.testData.ConvertRowsToStrings(tk.MustQuery("explain " + sql).Rows()) + c.Assert(strings.Index(rows[0], "IndexMergeJoin"), Equals, 0) + + sql = "select /*+ INL_HASH_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str" + tk.MustQuery(sql).Check(testkit.Rows("1 Alice 1 Bob")) + rows = s.testData.ConvertRowsToStrings(tk.MustQuery("explain " + sql).Rows()) + c.Assert(strings.Index(rows[0], "IndexHashJoin"), Equals, 0) + + sql = "select /*+ INL_JOIN(t1,t2) */ * from t1 join t2 partition(p0) on t1.c_int = t2.c_int and t1.c_str < t2.c_str" + tk.MustQuery(sql).Check(testkit.Rows("1 Alice 1 Bob")) + rows = s.testData.ConvertRowsToStrings(tk.MustQuery("explain " + sql).Rows()) + c.Assert(strings.Index(rows[0], "IndexJoin"), Equals, 0) +} diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index 34e3259bbb19b..ab91403ebd349 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -757,6 +757,8 @@ func (p *LogicalJoin) constructInnerTableScanTask( rangeDecidedBy: outerJoinKeys, KeepOrder: keepOrder, Desc: desc, + physicalTableID: ds.physicalTableID, + isPartition: ds.isPartition, }.Init(ds.ctx, ds.blockOffset) ts.SetSchema(ds.schema.Clone()) if rowCount <= 0 {