Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: make single partition table support index join on inner side #19151

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 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,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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only fix the old implementation, it's enough for the 4.0 branch (This is a release blocker).
I'll file another PR to fix for the new implementation.

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 @@ -842,6 +842,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