Skip to content

Commit

Permalink
sessionctx/variable: turn on range memory control by default (#38592)
Browse files Browse the repository at this point in the history
ref #37176
  • Loading branch information
xuyifangreeneyes committed Oct 21, 2022
1 parent f65f4ba commit 59886f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
19 changes: 10 additions & 9 deletions executor/set_test.go
Expand Up @@ -829,6 +829,16 @@ func TestSetVar(t *testing.T) {
tk.MustQuery("select @@global.tidb_auto_analyze_partition_batch_size").Check(testkit.Rows("1")) // min value is 1
tk.MustExec("set global tidb_auto_analyze_partition_batch_size = 9999")
tk.MustQuery("select @@global.tidb_auto_analyze_partition_batch_size").Check(testkit.Rows("1024")) // max value is 1024

// test tidb_opt_range_max_size
tk.MustQuery("select @@tidb_opt_range_max_size").Check(testkit.Rows("67108864"))
tk.MustExec("set global tidb_opt_range_max_size = -1")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect tidb_opt_range_max_size value: '-1'"))
tk.MustQuery("select @@global.tidb_opt_range_max_size").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_opt_range_max_size = 1048576")
tk.MustQuery("select @@global.tidb_opt_range_max_size").Check(testkit.Rows("1048576"))
tk.MustExec("set session tidb_opt_range_max_size = 2097152")
tk.MustQuery("select @@session.tidb_opt_range_max_size").Check(testkit.Rows("2097152"))
}

func TestGetSetNoopVars(t *testing.T) {
Expand Down Expand Up @@ -862,15 +872,6 @@ func TestGetSetNoopVars(t *testing.T) {
err = tk.ExecToErr("SET GLOBAL tidb_enable_noop_variables = 'warn'")
require.Error(t, err)
require.Equal(t, "[variable:1231]Variable 'tidb_enable_noop_variables' can't be set to the value of 'warn'", err.Error())

tk.MustQuery("select @@tidb_opt_range_max_size").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_opt_range_max_size = 1048576")
tk.MustQuery("select @@global.tidb_opt_range_max_size").Check(testkit.Rows("1048576"))
tk.MustExec("set global tidb_opt_range_max_size = -1")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect tidb_opt_range_max_size value: '-1'"))
tk.MustQuery("select @@global.tidb_opt_range_max_size").Check(testkit.Rows("0"))
tk.MustExec("set session tidb_opt_range_max_size = 2097152")
tk.MustQuery("select @@session.tidb_opt_range_max_size").Check(testkit.Rows("2097152"))
}

func TestTruncateIncorrectIntSessionVar(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions sessionctx/variable/BUILD.bazel
Expand Up @@ -48,6 +48,7 @@ go_library(
"//util/memory",
"//util/paging",
"//util/rowcodec",
"//util/size",
"//util/stmtsummary",
"//util/stringutil",
"//util/tableutil",
Expand Down
3 changes: 2 additions & 1 deletion sessionctx/variable/tidb_vars.go
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/tidb/util/mathutil"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/paging"
"github.com/pingcap/tidb/util/size"
"go.uber.org/atomic"
)

Expand Down Expand Up @@ -1059,7 +1060,7 @@ const (
DefTiDBRcWriteCheckTs = false
DefTiDBConstraintCheckInPlacePessimistic = true
DefTiDBForeignKeyChecks = false
DefTiDBOptRangeMaxSize = 0
DefTiDBOptRangeMaxSize = 64 * int64(size.MB) // 64 MB
DefTiDBCostModelVer = 1
DefTiDBServerMemoryLimitSessMinSize = 128 << 20
DefTiDBMergePartitionStatsConcurrency = 1
Expand Down

0 comments on commit 59886f5

Please sign in to comment.