From ae0f75054ec4db51762bf20860de21af9e0c9243 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 12 Oct 2023 17:37:20 +0800 Subject: [PATCH 1/4] *: add test for AnalyzePartitionMergeConcurrency Signed-off-by: Weizhen Wang --- .../handle/handletest/globalstats/BUILD.bazel | 3 ++- .../handletest/globalstats/globalstats_test.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/statistics/handle/handletest/globalstats/BUILD.bazel b/statistics/handle/handletest/globalstats/BUILD.bazel index 9a8e5cd524fbc..c985668b38319 100644 --- a/statistics/handle/handletest/globalstats/BUILD.bazel +++ b/statistics/handle/handletest/globalstats/BUILD.bazel @@ -8,10 +8,11 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 14, + shard_count = 15, deps = [ "//config", "//parser/model", + "//sessionctx", "//statistics/handle", "//testkit", "//testkit/testsetup", diff --git a/statistics/handle/handletest/globalstats/globalstats_test.go b/statistics/handle/handletest/globalstats/globalstats_test.go index 35b51502502d7..e700cb412844d 100644 --- a/statistics/handle/handletest/globalstats/globalstats_test.go +++ b/statistics/handle/handletest/globalstats/globalstats_test.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/parser/model" + "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/statistics/handle" "github.com/pingcap/tidb/testkit" "github.com/stretchr/testify/require" @@ -1114,7 +1115,7 @@ func TestGlobalStats(t *testing.T) { "└─TableFullScan 6.00 cop[tikv] table:t keep order:false")) } -func TestGlobalIndexStatistics(t *testing.T) { +func testGlobalIndexStatistics(t *testing.T, analyzePartitionMergeConcurrency int) { defer config.RestoreFunc()() config.UpdateGlobal(func(conf *config.Config) { conf.EnableGlobalIndex = true @@ -1127,6 +1128,8 @@ func TestGlobalIndexStatistics(t *testing.T) { h.SetLease(time.Millisecond) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + sctx := tk.Session().(sessionctx.Context) + sctx.GetSessionVars().AnalyzePartitionMergeConcurrency = analyzePartitionMergeConcurrency for i, version := range []string{"1", "2"} { tk.MustExec("set @@session.tidb_analyze_version = " + version) @@ -1192,3 +1195,11 @@ func TestGlobalIndexStatistics(t *testing.T) { "└─IndexRangeScan_11 4.00 cop[tikv] table:t, index:idx(b) range:[-inf,16), keep order:true")) } } + +func TestGlobalIndexStatistics(t *testing.T) { + testGlobalIndexStatistics(t, 1) +} + +func TestGlobalIndexStatisticsWithAnalyzePartitionMergeConcurrency(t *testing.T) { + testGlobalIndexStatistics(t, 2) +} From 632ade4cefc4512eb19de784d97cf6224a468f12 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 12 Oct 2023 19:11:28 +0800 Subject: [PATCH 2/4] update --- executor/analyze_test.go | 4 ++-- .../handle/handletest/globalstats/globalstats_test.go | 7 ++----- statistics/handle/util/util.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 6add0acab4be4..78c50a18308b4 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -150,8 +150,8 @@ func TestAnalyzePartitionTableByConcurrencyInDynamic(t *testing.T) { for _, tc := range testcases { concurrency := tc.concurrency fmt.Println("testcase ", concurrency) - tk.MustExec(fmt.Sprintf("set @@tidb_merge_partition_stats_concurrency=%v", concurrency)) - tk.MustQuery("select @@tidb_merge_partition_stats_concurrency").Check(testkit.Rows(concurrency)) + tk.MustExec(fmt.Sprintf("set @@global.tidb_merge_partition_stats_concurrency=%v", concurrency)) + tk.MustQuery("select @@global.tidb_merge_partition_stats_concurrency").Check(testkit.Rows(concurrency)) tk.MustExec(fmt.Sprintf("set @@tidb_analyze_partition_concurrency=%v", concurrency)) tk.MustQuery("select @@tidb_analyze_partition_concurrency").Check(testkit.Rows(concurrency)) diff --git a/statistics/handle/handletest/globalstats/globalstats_test.go b/statistics/handle/handletest/globalstats/globalstats_test.go index e700cb412844d..a1664fc220ae7 100644 --- a/statistics/handle/handletest/globalstats/globalstats_test.go +++ b/statistics/handle/handletest/globalstats/globalstats_test.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/parser/model" - "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/statistics/handle" "github.com/pingcap/tidb/testkit" "github.com/stretchr/testify/require" @@ -1128,12 +1127,10 @@ func testGlobalIndexStatistics(t *testing.T, analyzePartitionMergeConcurrency in h.SetLease(time.Millisecond) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") - sctx := tk.Session().(sessionctx.Context) - sctx.GetSessionVars().AnalyzePartitionMergeConcurrency = analyzePartitionMergeConcurrency for i, version := range []string{"1", "2"} { tk.MustExec("set @@session.tidb_analyze_version = " + version) - + tk.MustExec(fmt.Sprintf("set @@global.tidb_merge_partition_stats_concurrency=%d", analyzePartitionMergeConcurrency)) // analyze table t tk.MustExec("drop table if exists t") if i != 0 { @@ -1201,5 +1198,5 @@ func TestGlobalIndexStatistics(t *testing.T) { } func TestGlobalIndexStatisticsWithAnalyzePartitionMergeConcurrency(t *testing.T) { - testGlobalIndexStatistics(t, 2) + testGlobalIndexStatistics(t, 3) } diff --git a/statistics/handle/util/util.go b/statistics/handle/util/util.go index 181f7070129f1..06a190b2639ee 100644 --- a/statistics/handle/util/util.go +++ b/statistics/handle/util/util.go @@ -135,6 +135,16 @@ func UpdateSCtxVarsForStats(sctx sessionctx.Context) error { return err } sctx.GetSessionVars().SkipMissingPartitionStats = variable.TiDBOptOn(val) + + verInString, err = sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBMergePartitionStatsConcurrency) + if err != nil { + return err + } + ver, err = strconv.ParseInt(verInString, 10, 64) + if err != nil { + return err + } + sctx.GetSessionVars().AnalyzePartitionMergeConcurrency = int(ver) return nil } From 0d0ea77ca60997d11cefb68c32864b2d406f3690 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 12 Oct 2023 19:19:55 +0800 Subject: [PATCH 3/4] update --- statistics/handle/util/util.go | 1 - 1 file changed, 1 deletion(-) diff --git a/statistics/handle/util/util.go b/statistics/handle/util/util.go index 06a190b2639ee..dd581446880ea 100644 --- a/statistics/handle/util/util.go +++ b/statistics/handle/util/util.go @@ -135,7 +135,6 @@ func UpdateSCtxVarsForStats(sctx sessionctx.Context) error { return err } sctx.GetSessionVars().SkipMissingPartitionStats = variable.TiDBOptOn(val) - verInString, err = sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBMergePartitionStatsConcurrency) if err != nil { return err From f7f528896b81878a8ae9e1543fc957213f300e9f Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 12 Oct 2023 19:21:15 +0800 Subject: [PATCH 4/4] update --- statistics/handle/handletest/globalstats/BUILD.bazel | 3 +-- .../handletest/globalstats/globalstats_test.go | 12 ++---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/statistics/handle/handletest/globalstats/BUILD.bazel b/statistics/handle/handletest/globalstats/BUILD.bazel index c985668b38319..9a8e5cd524fbc 100644 --- a/statistics/handle/handletest/globalstats/BUILD.bazel +++ b/statistics/handle/handletest/globalstats/BUILD.bazel @@ -8,11 +8,10 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 15, + shard_count = 14, deps = [ "//config", "//parser/model", - "//sessionctx", "//statistics/handle", "//testkit", "//testkit/testsetup", diff --git a/statistics/handle/handletest/globalstats/globalstats_test.go b/statistics/handle/handletest/globalstats/globalstats_test.go index a1664fc220ae7..35b51502502d7 100644 --- a/statistics/handle/handletest/globalstats/globalstats_test.go +++ b/statistics/handle/handletest/globalstats/globalstats_test.go @@ -1114,7 +1114,7 @@ func TestGlobalStats(t *testing.T) { "└─TableFullScan 6.00 cop[tikv] table:t keep order:false")) } -func testGlobalIndexStatistics(t *testing.T, analyzePartitionMergeConcurrency int) { +func TestGlobalIndexStatistics(t *testing.T) { defer config.RestoreFunc()() config.UpdateGlobal(func(conf *config.Config) { conf.EnableGlobalIndex = true @@ -1130,7 +1130,7 @@ func testGlobalIndexStatistics(t *testing.T, analyzePartitionMergeConcurrency in for i, version := range []string{"1", "2"} { tk.MustExec("set @@session.tidb_analyze_version = " + version) - tk.MustExec(fmt.Sprintf("set @@global.tidb_merge_partition_stats_concurrency=%d", analyzePartitionMergeConcurrency)) + // analyze table t tk.MustExec("drop table if exists t") if i != 0 { @@ -1192,11 +1192,3 @@ func testGlobalIndexStatistics(t *testing.T, analyzePartitionMergeConcurrency in "└─IndexRangeScan_11 4.00 cop[tikv] table:t, index:idx(b) range:[-inf,16), keep order:true")) } } - -func TestGlobalIndexStatistics(t *testing.T) { - testGlobalIndexStatistics(t, 1) -} - -func TestGlobalIndexStatisticsWithAnalyzePartitionMergeConcurrency(t *testing.T) { - testGlobalIndexStatistics(t, 3) -}