From 88142b6838fb1db007c8d816d85bb8b6a532745c Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 12 Sep 2023 15:55:16 +0800 Subject: [PATCH 1/2] *: add bench for analyze Signed-off-by: Weizhen Wang --- executor/analyzetest/BUILD.bazel | 1 + .../test/analyzetest/analyze_bench_test.go | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 executor/test/analyzetest/analyze_bench_test.go diff --git a/executor/analyzetest/BUILD.bazel b/executor/analyzetest/BUILD.bazel index 5af1cae578a57..a4532ece56e2a 100644 --- a/executor/analyzetest/BUILD.bazel +++ b/executor/analyzetest/BUILD.bazel @@ -4,6 +4,7 @@ go_test( name = "analyzetest_test", timeout = "short", srcs = [ + "analyze_bench_test.go", "analyze_test.go", "main_test.go", ], diff --git a/executor/test/analyzetest/analyze_bench_test.go b/executor/test/analyzetest/analyze_bench_test.go new file mode 100644 index 0000000000000..a8159cb621e9c --- /dev/null +++ b/executor/test/analyzetest/analyze_bench_test.go @@ -0,0 +1,54 @@ +// Copyright 2023 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package analyzetest + +import ( + "fmt" + "testing" + + "github.com/pingcap/tidb/testkit" +) + +const ( + partitionCount = 1000 + partitioninterval = 100 +) + +func BenchmarkAnalyzePartition(b *testing.B) { + if testing.Short() { + b.Skip("it takes too much time to run") + } + store := testkit.CreateMockStore(b) + tk := testkit.NewTestKit(b, store) + tk.MustExec("use test") + tk.MustExec("set @@session.tidb_partition_prune_mode = 'dynamic'") + sql := "create table t(a int,b varchar(100),c int,INDEX idx_c(c)) PARTITION BY RANGE ( a ) (" + for n := partitioninterval; n < partitionCount*partitioninterval; n = n + partitioninterval { + sql += "PARTITION p" + fmt.Sprint(n) + " VALUES LESS THAN (" + fmt.Sprint(n) + ")," + } + sql += "PARTITION p" + fmt.Sprint(partitionCount*partitioninterval) + " VALUES LESS THAN MAXVALUE)" + tk.MustExec(sql) + // insert random data into table t + insertStr := "insert into t (a,b,c) values(0, 'abc', 0)" + for i := 1; i < 100000; i++ { + insertStr += fmt.Sprintf(" ,(%d, '%s', %d)", i, "abc", i) + } + insertStr += ";" + tk.MustExec(insertStr) + b.ResetTimer() + for i := 0; i < b.N; i++ { + tk.MustExec("analyze table t") + } +} From a7071b22ec6d990815d122cc2400f4730a8af1c6 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 6 Nov 2023 20:06:44 +0800 Subject: [PATCH 2/2] update Signed-off-by: Weizhen Wang --- executor/analyzetest/BUILD.bazel | 1 - executor/test/analyzetest/BUILD.bazel | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 executor/test/analyzetest/BUILD.bazel diff --git a/executor/analyzetest/BUILD.bazel b/executor/analyzetest/BUILD.bazel index a4532ece56e2a..5af1cae578a57 100644 --- a/executor/analyzetest/BUILD.bazel +++ b/executor/analyzetest/BUILD.bazel @@ -4,7 +4,6 @@ go_test( name = "analyzetest_test", timeout = "short", srcs = [ - "analyze_bench_test.go", "analyze_test.go", "main_test.go", ], diff --git a/executor/test/analyzetest/BUILD.bazel b/executor/test/analyzetest/BUILD.bazel new file mode 100644 index 0000000000000..97509acc1174c --- /dev/null +++ b/executor/test/analyzetest/BUILD.bazel @@ -0,0 +1,7 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +go_test( + name = "analyzetest_test", + srcs = ["analyze_bench_test.go"], + deps = ["//testkit"], +)