diff --git a/pkg/executor/join/hash_join_v2.go b/pkg/executor/join/hash_join_v2.go index e510e82c528f4..273649bfa3261 100644 --- a/pkg/executor/join/hash_join_v2.go +++ b/pkg/executor/join/hash_join_v2.go @@ -44,6 +44,10 @@ var ( enableHashJoinV2 = atomic.Bool{} ) +func init() { + enableHashJoinV2.Store(true) +} + // IsHashJoinV2Enabled return true if hash join v2 is enabled func IsHashJoinV2Enabled() bool { // sizeOfUintptr should always equal to sizeOfUnsafePointer, because according to golang's doc, @@ -865,20 +869,12 @@ func (*hashJoinRuntimeStatsV2) Tp() int { func (e *hashJoinRuntimeStatsV2) String() string { buf := bytes.NewBuffer(make([]byte, 0, 128)) if e.fetchAndBuildHashTable > 0 { - buf.WriteString("build_hash_table:{concurrency:") - buf.WriteString(strconv.Itoa(e.concurrent)) - buf.WriteString(", total:") + buf.WriteString("build_hash_table:{total:") buf.WriteString(execdetails.FormatDuration(e.fetchAndBuildHashTable)) buf.WriteString(", fetch:") buf.WriteString(execdetails.FormatDuration(time.Duration(int64(e.fetchAndBuildHashTable) - e.maxBuildHashTable - e.maxPartitionData))) - buf.WriteString(", partition:") - buf.WriteString(execdetails.FormatDuration(time.Duration(e.partitionData))) - buf.WriteString(", max partition:") - buf.WriteString(execdetails.FormatDuration(time.Duration(e.maxPartitionData))) buf.WriteString(", build:") buf.WriteString(execdetails.FormatDuration(time.Duration(e.buildHashTable))) - buf.WriteString(", max build:") - buf.WriteString(execdetails.FormatDuration(time.Duration(e.maxBuildHashTable))) buf.WriteString("}") } if e.probe > 0 { diff --git a/pkg/executor/test/issuetest/executor_issue_test.go b/pkg/executor/test/issuetest/executor_issue_test.go index aea2d3b601873..4566ba8f08453 100644 --- a/pkg/executor/test/issuetest/executor_issue_test.go +++ b/pkg/executor/test/issuetest/executor_issue_test.go @@ -178,7 +178,9 @@ func TestIssue30289(t *testing.T) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") require.NoError(t, failpoint.Enable(fpName, `return(true)`)) + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() defer func() { + join.SetEnableHashJoinV2(isHashJoinV2Enabled) require.NoError(t, failpoint.Disable(fpName)) }() useHashJoinV2 := []bool{true, false} @@ -197,7 +199,9 @@ func TestIssue51998(t *testing.T) { tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") require.NoError(t, failpoint.Enable(fpName, `return(true)`)) + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() defer func() { + join.SetEnableHashJoinV2(isHashJoinV2Enabled) require.NoError(t, failpoint.Disable(fpName)) }() useHashJoinV2 := []bool{true, false} @@ -617,6 +621,8 @@ func TestIssue42662(t *testing.T) { tk.MustExec("set global tidb_server_memory_limit='1600MB'") tk.MustExec("set global tidb_server_memory_limit_sess_min_size=128*1024*1024") tk.MustExec("set global tidb_mem_oom_action = 'cancel'") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() + defer join.SetEnableHashJoinV2(isHashJoinV2Enabled) useHashJoinV2 := []bool{true, false} for _, hashJoinV2 := range useHashJoinV2 { join.SetEnableHashJoinV2(hashJoinV2) diff --git a/pkg/executor/test/jointest/hashjoin/hash_join_test.go b/pkg/executor/test/jointest/hashjoin/hash_join_test.go index 34777fad30c7b..e96e7a580c7f4 100644 --- a/pkg/executor/test/jointest/hashjoin/hash_join_test.go +++ b/pkg/executor/test/jointest/hashjoin/hash_join_test.go @@ -411,6 +411,9 @@ func TestIssue20270(t *testing.T) { tk.MustExec("create table t1(c1 int, c2 int)") tk.MustExec("insert into t values(1,1),(2,2)") tk.MustExec("insert into t1 values(2,3),(4,4)") + enableHashJoinV2 := join.IsHashJoinV2Enabled() + join.SetEnableHashJoinV2(false) + defer join.SetEnableHashJoinV2(enableHashJoinV2) require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/executor/join/killedInJoin2Chunk", "return(true)")) err := tk.QueryToErr("select /*+ HASH_JOIN(t, t1) */ * from t left join t1 on t.c1 = t1.c1 where t.c1 = 1 or t1.c2 > 20") require.Equal(t, exeerrors.ErrQueryInterrupted, err) @@ -484,9 +487,10 @@ func TestFinalizeCurrentSegPanic(t *testing.T) { tk.MustExec("create table t2 (a int, b int, c int)") tk.MustExec("insert into t1 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") tk.MustExec("insert into t2 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() join.SetEnableHashJoinV2(true) defer func() { - join.SetEnableHashJoinV2(false) + join.SetEnableHashJoinV2(isHashJoinV2Enabled) }() fpName := "github.com/pingcap/tidb/pkg/executor/join/finalizeCurrentSegPanic" require.NoError(t, failpoint.Enable(fpName, "panic(\"finalizeCurrentSegPanic\")")) @@ -507,9 +511,10 @@ func TestSplitPartitionPanic(t *testing.T) { tk.MustExec("create table t2 (a int, b int, c int)") tk.MustExec("insert into t1 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") tk.MustExec("insert into t2 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() join.SetEnableHashJoinV2(true) defer func() { - join.SetEnableHashJoinV2(false) + join.SetEnableHashJoinV2(isHashJoinV2Enabled) }() fpName := "github.com/pingcap/tidb/pkg/executor/join/splitPartitionPanic" require.NoError(t, failpoint.Enable(fpName, "panic(\"splitPartitionPanic\")")) @@ -530,9 +535,10 @@ func TestProcessOneProbeChunkPanic(t *testing.T) { tk.MustExec("create table t2 (a int, b int, c int)") tk.MustExec("insert into t1 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") tk.MustExec("insert into t2 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() join.SetEnableHashJoinV2(true) defer func() { - join.SetEnableHashJoinV2(false) + join.SetEnableHashJoinV2(isHashJoinV2Enabled) }() fpName := "github.com/pingcap/tidb/pkg/executor/join/processOneProbeChunkPanic" require.NoError(t, failpoint.Enable(fpName, "panic(\"processOneProbeChunkPanic\")")) @@ -553,9 +559,10 @@ func TestCreateTasksPanic(t *testing.T) { tk.MustExec("create table t2 (a int, b int, c int)") tk.MustExec("insert into t1 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") tk.MustExec("insert into t2 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() join.SetEnableHashJoinV2(true) defer func() { - join.SetEnableHashJoinV2(false) + join.SetEnableHashJoinV2(isHashJoinV2Enabled) }() fpName := "github.com/pingcap/tidb/pkg/executor/join/createTasksPanic" require.NoError(t, failpoint.Enable(fpName, "panic(\"createTasksPanic\")")) @@ -576,9 +583,10 @@ func TestBuildHashTablePanic(t *testing.T) { tk.MustExec("create table t2 (a int, b int, c int)") tk.MustExec("insert into t1 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") tk.MustExec("insert into t2 values (1, 1, 1), (1, 2, 2), (2, 1, 3), (2, 2, 4)") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() join.SetEnableHashJoinV2(true) defer func() { - join.SetEnableHashJoinV2(false) + join.SetEnableHashJoinV2(isHashJoinV2Enabled) }() fpName := "github.com/pingcap/tidb/pkg/executor/join/buildHashTablePanic" require.NoError(t, failpoint.Enable(fpName, "panic(\"buildHashTablePanic\")")) @@ -599,9 +607,10 @@ func TestKillDuringProbe(t *testing.T) { tk.MustExec("create table t1(c1 int, c2 int)") tk.MustExec("insert into t values(1,1),(2,2)") tk.MustExec("insert into t1 values(2,3),(4,4)") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() join.SetEnableHashJoinV2(true) defer func() { - join.SetEnableHashJoinV2(false) + join.SetEnableHashJoinV2(isHashJoinV2Enabled) }() require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/executor/join/killedDuringProbe", "return(true)")) defer func() { @@ -632,9 +641,10 @@ func TestKillDuringBuild(t *testing.T) { tk.MustExec("create table t1(c1 int, c2 int)") tk.MustExec("insert into t values(1,1),(2,2)") tk.MustExec("insert into t1 values(2,3),(4,4)") + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() join.SetEnableHashJoinV2(true) defer func() { - join.SetEnableHashJoinV2(false) + join.SetEnableHashJoinV2(isHashJoinV2Enabled) }() require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/executor/join/killedDuringBuild", "return(true)")) defer func() { diff --git a/pkg/executor/test/seqtest/seq_executor_test.go b/pkg/executor/test/seqtest/seq_executor_test.go index df85c0db9f254..14f68aaa0abd3 100644 --- a/pkg/executor/test/seqtest/seq_executor_test.go +++ b/pkg/executor/test/seqtest/seq_executor_test.go @@ -1299,7 +1299,9 @@ func TestOOMPanicInHashJoinWhenFetchBuildRows(t *testing.T) { tk.MustExec("insert into t values(1,1),(2,2)") fpName := "github.com/pingcap/tidb/pkg/executor/join/errorFetchBuildSideRowsMockOOMPanic" require.NoError(t, failpoint.Enable(fpName, `panic("ERROR 1105 (HY000): Out Of Memory Quota![conn=1]")`)) + isHashJoinV2Enabled := join.IsHashJoinV2Enabled() defer func() { + join.SetEnableHashJoinV2(isHashJoinV2Enabled) require.NoError(t, failpoint.Disable(fpName)) }() useHashJoinV2 := []bool{true, false}