From c8c8d76d604ade1465ccf978e0f9bf0f13f6d83c Mon Sep 17 00:00:00 2001 From: Ryan Lv Date: Tue, 8 Oct 2019 16:20:52 +0800 Subject: [PATCH] executor,sessionctx: add correctness for system variables (#12311) --- executor/set_test.go | 13 +++++++++++++ sessionctx/variable/sysvar.go | 3 +++ sessionctx/variable/varsutil.go | 2 ++ 3 files changed, 18 insertions(+) diff --git a/executor/set_test.go b/executor/set_test.go index 0cd89fcb432aa..53529c6ef7f49 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -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;") diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 761ac487689ee..804d89c0f7abb 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -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)}, @@ -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. diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index d40b23dd8d52c..76626a3b8f33b 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -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":