Skip to content

Commit

Permalink
cherry pick pingcap#25672 to release-5.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
wshwsh12 authored and ti-srebot committed Jun 23, 2021
1 parent 0501813 commit 67568c7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
22 changes: 22 additions & 0 deletions executor/index_lookup_merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,25 @@ func (s *testSuite9) TestIssue20549(c *C) {
tk.MustQuery("SELECT /*+ HASH_JOIN(t1,t2) */ 1 from t1 left outer join t2 on t1.t2id=t2.id;\n").Check(
testkit.Rows("1"))
}
<<<<<<< HEAD
=======

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;").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"))
}
>>>>>>> 574de5e5e... planner: fix incorrect result of set type for merge join (#25672)
34 changes: 34 additions & 0 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ func (p *LogicalJoin) GetMergeJoin(prop *property.PhysicalProperty, schema *expr
joins := make([]PhysicalPlan, 0, len(p.leftProperties)+1)
// The leftProperties caches all the possible properties that are provided by its children.
leftJoinKeys, rightJoinKeys, isNullEQ, hasNullEQ := p.GetJoinKeys()
<<<<<<< HEAD
=======

// 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 || leftKey.RetType.Tp == mysql.TypeSet {
return nil
}
}
for _, rightKey := range rightJoinKeys {
if rightKey.RetType.Tp == mysql.TypeEnum || rightKey.RetType.Tp == mysql.TypeSet {
return nil
}
}

>>>>>>> 574de5e5e... planner: fix incorrect result of set type for merge join (#25672)
// TODO: support null equal join keys for merge join
if hasNullEQ {
return nil
Expand Down Expand Up @@ -514,6 +531,23 @@ func (p *LogicalJoin) constructIndexMergeJoin(
if len(join.InnerHashKeys) > len(join.InnerJoinKeys) {
return nil
}
<<<<<<< HEAD
=======

// 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 || innerKey.RetType.Tp == mysql.TypeSet {
return nil
}
}
for _, outerKey := range join.OuterJoinKeys {
if outerKey.RetType.Tp == mysql.TypeEnum || outerKey.RetType.Tp == mysql.TypeSet {
return nil
}
}

>>>>>>> 574de5e5e... planner: fix incorrect result of set type for merge join (#25672)
hasPrefixCol := false
for _, l := range join.IdxColLens {
if l != types.UnspecifiedLength {
Expand Down

0 comments on commit 67568c7

Please sign in to comment.