Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: set EnableOuterJoinReorder to false by default (#37264) #37280

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
7 changes: 7 additions & 0 deletions planner/core/rule_join_reorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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")
}

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

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