From f470c41e3bcfaa4b7058e029e7bb7f04ddd28479 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Fri, 14 Aug 2020 11:52:22 +0800 Subject: [PATCH 1/2] cherry pick #19151 to release-4.0 Signed-off-by: ti-srebot --- executor/index_lookup_merge_join_test.go | 25 ++++++++++++++++++++++++ planner/core/exhaust_physical_plans.go | 2 ++ 2 files changed, 27 insertions(+) diff --git a/executor/index_lookup_merge_join_test.go b/executor/index_lookup_merge_join_test.go index 3534a2fdc26e8..f7cd18ebd4293 100644 --- a/executor/index_lookup_merge_join_test.go +++ b/executor/index_lookup_merge_join_test.go @@ -64,3 +64,28 @@ func (s *testSuite9) TestIssue18631(c *C) { "2 2 2 2 2 2 2 2", "1 1 1 1 1 1 1 1")) } + +func (s *testSuiteWithData) TestIndexJoinOnSinglePartitionTable(c *C) { + // For issue 19145 + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("set @try_old_partition_implementation = 1") + 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 { From ea4f9d644f70e5a7ae3b957c7a46e9a515f05c68 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Fri, 14 Aug 2020 13:04:17 +0800 Subject: [PATCH 2/2] fix conflicts --- executor/index_lookup_merge_join_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/executor/index_lookup_merge_join_test.go b/executor/index_lookup_merge_join_test.go index f7cd18ebd4293..d979e60c0c44d 100644 --- a/executor/index_lookup_merge_join_test.go +++ b/executor/index_lookup_merge_join_test.go @@ -65,10 +65,9 @@ func (s *testSuite9) TestIssue18631(c *C) { "1 1 1 1 1 1 1 1")) } -func (s *testSuiteWithData) TestIndexJoinOnSinglePartitionTable(c *C) { +func (s *testSuiteAgg) TestIndexJoinOnSinglePartitionTable(c *C) { // For issue 19145 tk := testkit.NewTestKitWithInit(c, s.store) - tk.MustExec("set @try_old_partition_implementation = 1") 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 )")