diff --git a/cmd/explaintest/r/clustered_index.result b/cmd/explaintest/r/clustered_index.result index 665c60e40d2b0..c9bfb61c93604 100644 --- a/cmd/explaintest/r/clustered_index.result +++ b/cmd/explaintest/r/clustered_index.result @@ -1,3 +1,4 @@ +set @@tidb_enable_outer_join_reorder=true; drop database if exists with_cluster_index; create database with_cluster_index; drop database if exists wout_cluster_index; @@ -127,3 +128,4 @@ StreamAgg_17 1.00 root funcs:count(Column#9)->Column#7 └─IndexReader_18 1.00 root index:StreamAgg_9 └─StreamAgg_9 1.00 cop[tikv] funcs:count(1)->Column#9 └─IndexRangeScan_16 109.70 cop[tikv] table:tbl_0, index:idx_3(col_0) range:[803163,+inf], keep order:false +set @@tidb_enable_outer_join_reorder=false; diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index 636139109644d..a31c03782bbfb 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -1,3 +1,4 @@ +set @@tidb_enable_outer_join_reorder=true; DROP TABLE IF EXISTS t; CREATE TABLE t ( c1 int, @@ -654,3 +655,4 @@ create table t3(a char(10), primary key (a)); insert into t3 values ('a'); select * from t3 where a > 0x80; Error 1105: Cannot convert string '\x80' from binary to utf8mb4 +set @@tidb_enable_outer_join_reorder=false; diff --git a/cmd/explaintest/t/clustered_index.test b/cmd/explaintest/t/clustered_index.test index 9415781f7caf1..606a768f5b8d4 100644 --- a/cmd/explaintest/t/clustered_index.test +++ b/cmd/explaintest/t/clustered_index.test @@ -1,3 +1,4 @@ +set @@tidb_enable_outer_join_reorder=true; drop database if exists with_cluster_index; create database with_cluster_index; drop database if exists wout_cluster_index; @@ -53,3 +54,4 @@ explain select count(*) from wout_cluster_index.tbl_0 where col_0 <= 0 ; explain select count(*) from with_cluster_index.tbl_0 where col_0 >= 803163 ; explain select count(*) from wout_cluster_index.tbl_0 where col_0 >= 803163 ; +set @@tidb_enable_outer_join_reorder=false; diff --git a/cmd/explaintest/t/select.test b/cmd/explaintest/t/select.test index 64ee824830b51..dbb505bb250f0 100644 --- a/cmd/explaintest/t/select.test +++ b/cmd/explaintest/t/select.test @@ -1,3 +1,4 @@ +set @@tidb_enable_outer_join_reorder=true; DROP TABLE IF EXISTS t; CREATE TABLE t ( @@ -279,3 +280,4 @@ create table t3(a char(10), primary key (a)); insert into t3 values ('a'); --error 1105 select * from t3 where a > 0x80; +set @@tidb_enable_outer_join_reorder=false; diff --git a/planner/core/rule_join_reorder_test.go b/planner/core/rule_join_reorder_test.go index c7768ccf04ce4..0659c0a887d43 100644 --- a/planner/core/rule_join_reorder_test.go +++ b/planner/core/rule_join_reorder_test.go @@ -77,6 +77,7 @@ func TestLeadingJoinHint(t *testing.T) { tk.MustExec("create table t6(a int, b int, key(a));") tk.MustExec("create table t7(a int, b int, key(a));") tk.MustExec("create table t8(a int, b int, key(a));") + tk.MustExec("set @@tidb_enable_outer_join_reorder=true") runJoinReorderTestData(t, tk, "TestLeadingJoinHint") // test cases for outer join @@ -117,6 +118,8 @@ func TestJoinOrderHint(t *testing.T) { tk.MustExec("create table t7(a int, b int, key(a));") tk.MustExec("create table t8(a int, b int, key(a));") + tk.MustExec("set @@tidb_enable_outer_join_reorder=true") + // test cases for using the leading hint and straight_join hint at the same time tk.MustExec("select /*+ leading(t1) straight_join() */ * from t1 join t2 on t1.a=t2.a join t3 on t2.b=t3.b") tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1815 We can only use the straight_join hint, when we use the leading hint and straight_join hint at the same time, all leading hints will be invalid")) @@ -239,6 +242,7 @@ func TestJoinOrderHint4StaticPartitionTable(t *testing.T) { tk.MustExec(`create table t3(a int, b int) partition by hash(b) partitions 3`) tk.MustExec(`set @@tidb_partition_prune_mode="static"`) + tk.MustExec("set @@tidb_enable_outer_join_reorder=true") runJoinReorderTestData(t, tk, "TestJoinOrderHint4StaticPartitionTable") } @@ -255,6 +259,7 @@ func TestJoinOrderHint4DynamicPartitionTable(t *testing.T) { tk.MustExec(`create table t3(a int, b int) partition by hash(b) partitions 3`) tk.MustExec(`set @@tidb_partition_prune_mode="dynamic"`) + tk.MustExec("set @@tidb_enable_outer_join_reorder=true") runJoinReorderTestData(t, tk, "TestJoinOrderHint4DynamicPartitionTable") } @@ -274,6 +279,7 @@ func TestJoinOrderHint4DifferentJoinType(t *testing.T) { tk.MustExec("create table t6(a int, b int, key(a));") tk.MustExec("create table t7(a int, b int, key(a));") tk.MustExec("create table t8(a int, b int, key(a));") + tk.MustExec("set @@tidb_enable_outer_join_reorder=true") runJoinReorderTestData(t, tk, "TestJoinOrderHint4DifferentJoinType") } @@ -288,6 +294,7 @@ func TestJoinOrderHint4TiFlash(t *testing.T) { tk.MustExec("create table t1(a int, b int, key(a));") tk.MustExec("create table t2(a int, b int, key(a));") tk.MustExec("create table t3(a int, b int, key(a));") + tk.MustExec("set @@tidb_enable_outer_join_reorder=true") // Create virtual tiflash replica info. dom := domain.GetDomain(tk.Session()) diff --git a/planner/core/rule_result_reorder_test.go b/planner/core/rule_result_reorder_test.go index 567c1488508d9..82177726ddce1 100644 --- a/planner/core/rule_result_reorder_test.go +++ b/planner/core/rule_result_reorder_test.go @@ -166,6 +166,7 @@ func TestOrderedResultModeOnJoin(t *testing.T) { tk.MustExec("drop table if exists t2") tk.MustExec("create table t1 (a int primary key, b int, c int, d int, key(b))") tk.MustExec("create table t2 (a int primary key, b int, c int, d int, key(b))") + tk.MustExec("set @@tidb_enable_outer_join_reorder=true") runTestData(t, tk, "TestOrderedResultModeOnJoin") } diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 169b1be0feec7..ac9e232f85dd8 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -196,7 +196,7 @@ var defaultSysVars = []*SysVar{ s.OptimizerSelectivityLevel = tidbOptPositiveInt32(val, DefTiDBOptimizerSelectivityLevel) return nil }}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptimizerEnableOuterJoinReorder, Value: BoolToOnOff(DefTiDBEnableOuterJoinReorder), skipInit: true, Type: TypeBool, SetSession: func(s *SessionVars, val string) error { + {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptimizerEnableOuterJoinReorder, Value: BoolToOnOff(DefTiDBEnableOuterJoinReorder), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { s.EnableOuterJoinReorder = TiDBOptOn(val) return nil }}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 12916ed13e874..9141431c95b12 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -775,7 +775,7 @@ const ( DefBroadcastJoinThresholdCount = 10 * 1024 DefTiDBOptimizerSelectivityLevel = 0 DefTiDBOptimizerEnableNewOFGB = false - DefTiDBEnableOuterJoinReorder = true + DefTiDBEnableOuterJoinReorder = false DefTiDBAllowBatchCop = 1 DefTiDBAllowMPPExecution = true DefTiDBHashExchangeWithNewCollation = true diff --git a/sessionctx/variable/varsutil_test.go b/sessionctx/variable/varsutil_test.go index 28957027b6129..9d30df7604a7f 100644 --- a/sessionctx/variable/varsutil_test.go +++ b/sessionctx/variable/varsutil_test.go @@ -242,6 +242,9 @@ func TestVarsutil(t *testing.T) { err = SetSessionSystemVar(v, TiDBOptimizerEnableOuterJoinReorder, "OFF") require.NoError(t, err) require.Equal(t, false, v.EnableOuterJoinReorder) + err = v.SetSystemVar(TiDBOptimizerEnableOuterJoinReorder, "ON") + require.NoError(t, err) + require.Equal(t, true, v.EnableOuterJoinReorder) require.Equal(t, DefTiDBOptimizerEnableNewOFGB, v.OptimizerEnableNewOnlyFullGroupByCheck) err = SetSessionSystemVar(v, TiDBOptimizerEnableNewOnlyFullGroupByCheck, "off")