Skip to content

Commit 851af35

Browse files
authored
planner: set the minimum Instance Plan Cache Mem Size to 100MiB (#57382)
ref #54057
1 parent ed2d749 commit 851af35

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

pkg/planner/core/casetest/instanceplancache/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ go_test(
1212
"others_test.go",
1313
],
1414
flaky = True,
15-
shard_count = 34,
15+
shard_count = 35,
1616
deps = [
1717
"//pkg/parser/auth",
1818
"//pkg/testkit",

pkg/planner/core/casetest/instanceplancache/others_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ import (
2626
"github.com/stretchr/testify/require"
2727
)
2828

29+
func TestInstancePlanCacheMinSize(t *testing.T) {
30+
store := testkit.CreateMockStore(t)
31+
tk := testkit.NewTestKit(t, store)
32+
tk.MustExecToErr("set global tidb_instance_plan_cache_max_size=0")
33+
tk.MustExecToErr("set global tidb_instance_plan_cache_max_size=1")
34+
tk.MustExecToErr("set global tidb_instance_plan_cache_max_size=101KiB")
35+
tk.MustExecToErr("set global tidb_instance_plan_cache_max_size=10001KiB")
36+
tk.MustExecToErr("set global tidb_instance_plan_cache_max_size=99MiB")
37+
tk.MustExec("set global tidb_instance_plan_cache_max_size=100MiB")
38+
tk.MustExec("set global tidb_instance_plan_cache_max_size=101MiB")
39+
tk.MustExec("set global tidb_instance_plan_cache_max_size=2000000KiB")
40+
}
41+
2942
func TestInstancePlanCacheVars(t *testing.T) {
3043
store := testkit.CreateMockStore(t)
3144
tk := testkit.NewTestKit(t, store)
@@ -45,8 +58,8 @@ func TestInstancePlanCacheVars(t *testing.T) {
4558
tk.MustExecToErr(`set global tidb_instance_plan_cache_max_size=-1`)
4659
tk.MustExecToErr(`set global tidb_instance_plan_cache_max_size=-1111111111111`)
4760
tk.MustExecToErr(`set global tidb_instance_plan_cache_max_size=dslfj`)
48-
tk.MustExec(`set global tidb_instance_plan_cache_max_size=123456`)
49-
tk.MustQuery(`select @@tidb_instance_plan_cache_max_size`).Check(testkit.Rows("123456"))
61+
tk.MustExec(`set global tidb_instance_plan_cache_max_size=1234560000`)
62+
tk.MustQuery(`select @@tidb_instance_plan_cache_max_size`).Check(testkit.Rows("1234560000"))
5063
tk.MustExec(`set global tidb_instance_plan_cache_reserved_percentage=-1`)
5164
tk.MustQuery(`show warnings`).Check(testkit.Rows(`Warning 1292 Truncated incorrect tidb_instance_plan_cache_reserved_percentage value: '-1'`))
5265
tk.MustExec(`set global tidb_instance_plan_cache_reserved_percentage=1.1100`)

pkg/sessionctx/variable/sysvar.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,9 @@ var defaultSysVars = []*SysVar{
14191419
if str == "" || v < 0 {
14201420
return errors.Errorf("invalid tidb_instance_plan_cache_max_mem_size value %s", val)
14211421
}
1422+
if v < MinTiDBInstancePlanCacheMemSize {
1423+
return errors.Errorf("tidb_instance_plan_cache_max_mem_size should be at least 100MiB")
1424+
}
14221425
InstancePlanCacheMaxMemSize.Store(int64(v))
14231426
return nil
14241427
}},

pkg/sessionctx/variable/tidb_vars.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ const (
14691469
DefTiDBNonPreparedPlanCacheSize = 100
14701470
DefTiDBPlanCacheMaxPlanSize = 2 * size.MB
14711471
DefTiDBInstancePlanCacheMaxMemSize = 100 * size.MB
1472+
MinTiDBInstancePlanCacheMemSize = 100 * size.MB
14721473
DefTiDBInstancePlanCacheReservedPercentage = 0.1
14731474
// MaxDDLReorgBatchSize is exported for testing.
14741475
MaxDDLReorgBatchSize int32 = 10240

0 commit comments

Comments
 (0)