Skip to content

Commit

Permalink
planner: fix incorrect result of set type for merge join (#25672) (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jun 25, 2021
1 parent 4246444 commit 9d94645
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 9 additions & 1 deletion executor/index_lookup_merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *testSuite9) TestIssue20549(c *C) {
testkit.Rows("1"))
}

func (s *testSuite9) TestIssue24473(c *C) {
func (s *testSuite9) TestIssue24473AndIssue25669(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists x, t2, t3")
tk.MustExec("CREATE TABLE `x` ( `a` enum('y','b','1','x','0','null') DEFAULT NULL, KEY `a` (`a`));")
Expand All @@ -168,4 +168,12 @@ func (s *testSuite9) TestIssue24473(c *C) {
testkit.Rows("b b", "x x", "x x", "x x", "x x", "y y"))
tk.MustQuery("SELECT /*+ inl_merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a;").Sort().Check(
testkit.Rows("b b", "x x", "x x", "x x", "x x", "y y"))

tk.MustExec("drop table if exists x, t2, t3")
tk.MustExec("CREATE TABLE `x` ( `a` set('y','b','1','x','0','null') DEFAULT NULL, KEY `a` (`a`));")
tk.MustExec("insert into x values(\"x\"),(\"x\"),(\"b\"),(\"y\");")
tk.MustQuery("SELECT /*+ merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a;").Sort().Check(
testkit.Rows("b b", "x x", "x x", "x x", "x x", "y y"))
tk.MustQuery("SELECT /*+ inl_merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a;").Sort().Check(
testkit.Rows("b b", "x x", "x x", "x x", "x x", "y y"))
}
14 changes: 8 additions & 6 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ func (p *LogicalJoin) GetMergeJoin(prop *property.PhysicalProperty, schema *expr
// The leftProperties caches all the possible properties that are provided by its children.
leftJoinKeys, rightJoinKeys, isNullEQ, hasNullEQ := p.GetJoinKeys()

// EnumType Unsupported: merge join conflicts with index order. ref: https://github.com/pingcap/tidb/issues/24473
// EnumType/SetType Unsupported: merge join conflicts with index order.
// ref: https://github.com/pingcap/tidb/issues/24473, https://github.com/pingcap/tidb/issues/25669
for _, leftKey := range leftJoinKeys {
if leftKey.RetType.Tp == mysql.TypeEnum {
if leftKey.RetType.Tp == mysql.TypeEnum || leftKey.RetType.Tp == mysql.TypeSet {
return nil
}
}
for _, rightKey := range rightJoinKeys {
if rightKey.RetType.Tp == mysql.TypeEnum {
if rightKey.RetType.Tp == mysql.TypeEnum || rightKey.RetType.Tp == mysql.TypeSet {
return nil
}
}
Expand Down Expand Up @@ -528,14 +529,15 @@ func (p *LogicalJoin) constructIndexMergeJoin(
return nil
}

// EnumType Unsupported: merge join conflicts with index order. ref: https://github.com/pingcap/tidb/issues/24473
// EnumType/SetType Unsupported: merge join conflicts with index order.
// ref: https://github.com/pingcap/tidb/issues/24473, https://github.com/pingcap/tidb/issues/25669
for _, innerKey := range join.InnerJoinKeys {
if innerKey.RetType.Tp == mysql.TypeEnum {
if innerKey.RetType.Tp == mysql.TypeEnum || innerKey.RetType.Tp == mysql.TypeSet {
return nil
}
}
for _, outerKey := range join.OuterJoinKeys {
if outerKey.RetType.Tp == mysql.TypeEnum {
if outerKey.RetType.Tp == mysql.TypeEnum || outerKey.RetType.Tp == mysql.TypeSet {
return nil
}
}
Expand Down

0 comments on commit 9d94645

Please sign in to comment.