From df4a6f4b9d9b65adaadf4bf8744438f48c02a956 Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Mon, 13 Feb 2023 19:31:26 +0800 Subject: [PATCH 1/2] add --- planner/core/binary_plan_test.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/planner/core/binary_plan_test.go b/planner/core/binary_plan_test.go index 95c67990b09be..46815d7ab620b 100644 --- a/planner/core/binary_plan_test.go +++ b/planner/core/binary_plan_test.go @@ -165,6 +165,12 @@ func TestBinaryPlanSwitch(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) + origin := tk.MustQuery("SELECT @@global.tidb_generate_binary_plan") + originStr := origin.Rows()[0][0].(string) + defer func() { + tk.MustExec("set @@global.tidb_generate_binary_plan = '" + originStr + "'") + }() + tk.MustExec("use test") // 1. assert binary plan is generated if the variable is turned on tk.MustExec("set global tidb_generate_binary_plan = 1") @@ -234,6 +240,16 @@ func TestTooLongBinaryPlan(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) + origin := tk.MustQuery("SELECT @@global.tidb_enable_stmt_summary") + originStr := origin.Rows()[0][0].(string) + defer func() { + tk.MustExec("set @@global.tidb_enable_stmt_summary = '" + originStr + "'") + }() + + // Trigger clear the stmt summary in memory to prevent this case from being affected by other cases. + tk.MustExec("set global tidb_enable_stmt_summary = 0") + tk.MustExec("set global tidb_enable_stmt_summary = 1") + tk.MustExec("use test") tk.MustExec("drop table if exists th") tk.MustExec("set @@session.tidb_enable_table_partition = 1") @@ -276,7 +292,6 @@ func TestTooLongBinaryPlan(t *testing.T) { } // TestLongBinaryPlan asserts that if the binary plan is smaller than 1024*1024 bytes, it should be output to both slow query and stmt summary. -// The size of the binary plan in this test case is designed to be larger than 1024*1024*0.85 bytes but smaller than 1024*1024 bytes. func TestLongBinaryPlan(t *testing.T) { originCfg := config.GetGlobalConfig() newCfg := *originCfg @@ -301,7 +316,7 @@ func TestLongBinaryPlan(t *testing.T) { tk.MustExec("drop table if exists th") tk.MustExec("set @@session.tidb_enable_table_partition = 1") tk.MustExec(`set @@tidb_partition_prune_mode='` + string(variable.Static) + `'`) - tk.MustExec("create table th (i int, a int,b int, c int, index (a)) partition by hash (a) partitions 1700;") + tk.MustExec("create table th (i int, a int,b int, c int, index (a)) partition by hash (a) partitions 1000;") tk.MustQuery("select count(*) from th t1 join th t2 join th t3 join th t4 join th t5 join th t6 where t1.i=t2.a and t1.i=t3.i and t3.i=t4.i and t4.i=t5.i and t5.i=t6.i") result := testdata.ConvertRowsToStrings(tk.MustQuery("select binary_plan from information_schema.slow_query " + @@ -309,10 +324,9 @@ func TestLongBinaryPlan(t *testing.T) { "limit 1;").Rows()) require.Len(t, result, 1) s1 := result[0] - // The binary plan in this test case is expected to be slightly smaller than MaxEncodedPlanSizeInBytes. + // The binary plan in this test case is expected to be smaller than MaxEncodedPlanSizeInBytes. // If the size of the binary plan changed and this case failed in the future, you can adjust the partition numbers in the CREATE TABLE statement above. require.Less(t, len(s1), stmtsummary.MaxEncodedPlanSizeInBytes) - require.Greater(t, len(s1), int(float64(stmtsummary.MaxEncodedPlanSizeInBytes)*0.85)) b, err := base64.StdEncoding.DecodeString(s1) require.NoError(t, err) b, err = snappy.Decode(nil, b) @@ -511,6 +525,12 @@ func TestUnnecessaryBinaryPlanInSlowLog(t *testing.T) { require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil)) tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name())) + origin := tk.MustQuery("SELECT @@global.tidb_slow_log_threshold") + originStr := origin.Rows()[0][0].(string) + defer func() { + tk.MustExec("set @@global.tidb_slow_log_threshold = '" + originStr + "'") + }() + tk.MustExec("use test") tk.MustExec("drop table if exists th") tk.MustExec("set global tidb_slow_log_threshold = 1;") From c4b92923d6e67800a910034033e5c9268aa4779b Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Mon, 13 Feb 2023 21:18:18 +0800 Subject: [PATCH 2/2] update timeout --- planner/core/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/BUILD.bazel b/planner/core/BUILD.bazel index c0691506207e0..e6a8af98ae93a 100644 --- a/planner/core/BUILD.bazel +++ b/planner/core/BUILD.bazel @@ -158,7 +158,7 @@ go_library( go_test( name = "core_test", - timeout = "moderate", + timeout = "short", srcs = [ "binary_plan_test.go", "cbo_test.go",