Skip to content

Commit

Permalink
planner: set EnableOuterJoinReorder to false by default (pingcap#37264)…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot committed Aug 22, 2022
1 parent be9be01 commit daf2b17
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/explaintest/r/clustered_index.result
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
2 changes: 2 additions & 0 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set @@tidb_enable_outer_join_reorder=true;
DROP TABLE IF EXISTS t;
CREATE TABLE t (
c1 int,
Expand Down Expand Up @@ -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;
2 changes: 2 additions & 0 deletions cmd/explaintest/t/clustered_index.test
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
2 changes: 2 additions & 0 deletions cmd/explaintest/t/select.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set @@tidb_enable_outer_join_reorder=true;
DROP TABLE IF EXISTS t;

CREATE TABLE t (
Expand Down Expand Up @@ -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;
5 changes: 5 additions & 0 deletions planner/core/rule_join_reorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand All @@ -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")
}
Expand All @@ -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())
Expand Down Expand Up @@ -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")
}

Expand Down
1 change: 1 addition & 0 deletions planner/core/rule_result_reorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}},
Expand Down
1 change: 0 additions & 1 deletion sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,6 @@ func TestSkipInitIsUsed(t *testing.T) {
TiDBEnableChunkRPC,
TxnIsolationOneShot,
TiDBOptimizerSelectivityLevel,
TiDBOptimizerEnableOuterJoinReorder,
TiDBDDLReorgPriority,
TiDBSlowQueryFile,
TiDBWaitSplitRegionFinish,
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ const (
DefBroadcastJoinThresholdCount = 10 * 1024
DefTiDBOptimizerSelectivityLevel = 0
DefTiDBOptimizerEnableNewOFGB = false
DefTiDBEnableOuterJoinReorder = true
DefTiDBEnableOuterJoinReorder = false
DefTiDBAllowBatchCop = 1
DefTiDBAllowMPPExecution = true
DefTiDBHashExchangeWithNewCollation = true
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/variable/varsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit daf2b17

Please sign in to comment.