Skip to content

Commit

Permalink
executor: enable hash join v2 for temporary test (pingcap#55821)
Browse files Browse the repository at this point in the history
  • Loading branch information
windtalker authored Sep 3, 2024
1 parent 0816166 commit 2b54db5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
14 changes: 5 additions & 9 deletions pkg/executor/join/hash_join_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/executor/test/issuetest/executor_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 17 additions & 7 deletions pkg/executor/test/jointest/hashjoin/hash_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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\")"))
Expand All @@ -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\")"))
Expand All @@ -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\")"))
Expand All @@ -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\")"))
Expand All @@ -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\")"))
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions pkg/executor/test/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 2b54db5

Please sign in to comment.