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 {