From daf2b17cdfe30c02ce282361009fb5bdb05f2b0e Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Mon, 22 Aug 2022 21:28:20 +0800 Subject: [PATCH] planner: set EnableOuterJoinReorder to false by default (#37264) (#37281) ref pingcap/tidb#37238 --- cmd/explaintest/r/clustered_index.result | 2 ++ cmd/explaintest/r/select.result | 2 ++ cmd/explaintest/t/clustered_index.test | 2 ++ cmd/explaintest/t/select.test | 2 ++ planner/core/rule_join_reorder_test.go | 5 +++++ planner/core/rule_result_reorder_test.go | 1 + sessionctx/variable/sysvar.go | 2 +- sessionctx/variable/sysvar_test.go | 1 - sessionctx/variable/tidb_vars.go | 2 +- sessionctx/variable/varsutil_test.go | 3 +++ 10 files changed, 19 insertions(+), 3 deletions(-) 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 01bd43ecf941c..31d685a1bc6bd 100644 --- a/planner/core/rule_join_reorder_test.go +++ b/planner/core/rule_join_reorder_test.go @@ -233,6 +233,7 @@ func TestJoinOrderHint4StaticPartitionTable(t *testing.T) { tk.MustExec(`create table t6(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") } @@ -252,6 +253,7 @@ func TestJoinOrderHint4DynamicPartitionTable(t *testing.T) { tk.MustExec(`create table t6(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") } @@ -271,6 +273,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 +291,7 @@ func TestJoinOrderHint4TiFlash(t *testing.T) { tk.MustExec("create table t4(a int, b int, key(a));") tk.MustExec("create table t5(a int, b int, key(a));") tk.MustExec("create table t6(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()) @@ -346,6 +350,7 @@ func TestLeadingJoinHint4OuterJoin(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, "TestLeadingJoinHint4OuterJoin") } 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 d243379978d42..d286e40a82c33 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -216,7 +216,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/sysvar_test.go b/sessionctx/variable/sysvar_test.go index ebf0fd2587624..0e81191d9829e 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -723,7 +723,6 @@ func TestSkipInitIsUsed(t *testing.T) { TiDBEnableChunkRPC, TxnIsolationOneShot, TiDBOptimizerSelectivityLevel, - TiDBOptimizerEnableOuterJoinReorder, TiDBDDLReorgPriority, TiDBSlowQueryFile, TiDBWaitSplitRegionFinish, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 990e72761740c..49d4da41dc7d7 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -867,7 +867,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 49362e0fc3969..24e6536db27a5 100644 --- a/sessionctx/variable/varsutil_test.go +++ b/sessionctx/variable/varsutil_test.go @@ -241,6 +241,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")