Skip to content

Commit

Permalink
executor,sessionctx: add correctness for system variables (#12… (#12588)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Lv authored and zz-jason committed Oct 10, 2019
1 parent b103dff commit 68e70bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@ func (s *testSuite2) TestValidateSetVar(c *C) {
_, err = tk.Exec("set @@global.max_connections='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)

tk.MustExec("set @@global.thread_pool_size=65")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect thread_pool_size value: '65'"))
result = tk.MustQuery("select @@global.thread_pool_size;")
result.Check(testkit.Rows("64"))

tk.MustExec("set @@global.thread_pool_size=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect thread_pool_size value: '-1'"))
result = tk.MustQuery("select @@global.thread_pool_size;")
result.Check(testkit.Rows("1"))

_, err = tk.Exec("set @@global.thread_pool_size='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)

tk.MustExec("set @@global.max_allowed_packet=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_allowed_packet value: '-1'"))
result = tk.MustQuery("select @@global.max_allowed_packet;")
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ var defaultSysVars = []*SysVar{
{ScopeGlobal, "innodb_online_alter_log_max_size", "134217728"},
{ScopeSession, WarningCount, "0"},
{ScopeSession, ErrorCount, "0"},
{ScopeGlobal, "thread_pool_size", "16"},
/* TiDB specific variables */
{ScopeSession, TiDBSnapshot, ""},
{ScopeSession, TiDBOptAggPushDown, BoolToIntStr(DefOptAggPushDown)},
Expand Down Expand Up @@ -947,6 +948,8 @@ const (
InnodbTableLocks = "innodb_table_locks"
// InnodbStatusOutput is the name for 'innodb_status_output' system variable.
InnodbStatusOutput = "innodb_status_output"
// ThreadPoolSize is the name of 'thread_pool_size' variable.
ThreadPoolSize = "thread_pool_size"
)

// GlobalVarAccessor is the interface for accessing global scope system and status variables.
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
return value, ErrWrongValueForVar.GenWithStackByArgs(name, value)
case MaxExecutionTime:
return checkUInt64SystemVar(name, value, 0, math.MaxUint64, vars)
case ThreadPoolSize:
return checkUInt64SystemVar(name, value, 1, 64, vars)
case TiDBEnableTablePartition:
switch {
case strings.EqualFold(value, "ON") || value == "1":
Expand Down

0 comments on commit 68e70bf

Please sign in to comment.