diff --git a/executor/index_lookup_merge_join_test.go b/executor/index_lookup_merge_join_test.go index 2158026f1966f..1817dca79a3ae 100644 --- a/executor/index_lookup_merge_join_test.go +++ b/executor/index_lookup_merge_join_test.go @@ -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")) } diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index 59b635eada379..9dffea4e21c7c 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -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 } } @@ -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 } }