Skip to content

Commit

Permalink
planner: fix incorrect result of set type for merge join (#25672)
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 authored Jun 23, 2021
1 parent 8c33190 commit 574de5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
18 changes: 13 additions & 5 deletions executor/index_lookup_merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,21 @@ 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`));")
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;").Check(
testkit.Rows("y y", "b b", "x x", "x x", "x x", "x x"))
tk.MustQuery("SELECT /*+ inl_merge_join (t2,t3) */ t2.a,t3.a FROM x t2 inner join x t3 on t2.a = t3.a;").Check(
testkit.Rows("y y", "b b", "x x", "x x", "x x", "x x"))
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"))

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 @@ -150,14 +150,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 @@ -529,14 +530,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 574de5e

Please sign in to comment.