Skip to content

Commit

Permalink
planner: make single partition table support index join on inner side (
Browse files Browse the repository at this point in the history
…#19151) (#19197)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Aug 21, 2020
1 parent c5b7658 commit fb95293
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions executor/index_lookup_merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fb95293

Please sign in to comment.