Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor,sessionctx: Add correctness for more system variables #7196

Merged
merged 28 commits into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3e76be6
executor,sessionctx: Add correctness for more system variables
spongedu Jul 30, 2018
f0f0208
Code refine
spongedu Jul 30, 2018
261495a
Fix tests
spongedu Jul 30, 2018
2e5585e
Merge remote-tracking branch 'upstream/master' into dc_0731
spongedu Jul 31, 2018
b6eef7f
Add more check
spongedu Jul 31, 2018
281080a
Merge branch 'master' into dc_0731
spongedu Aug 1, 2018
e79a0d0
Merge branch 'master' into dc_0731
spongedu Aug 3, 2018
ea0dc36
Merge branch 'master' into dc_0731
spongedu Aug 6, 2018
7344060
Merge remote-tracking branch 'upstream/master' into dc_0731
spongedu Aug 9, 2018
4c9ff91
Code format refine
spongedu Aug 9, 2018
deb953e
Merge branch 'master' into dc_0731
zz-jason Aug 9, 2018
bcadbc0
bug fix
spongedu Aug 10, 2018
a72f646
Merge branch 'dc_0731' of github.com:spongedu/tidb into dc_0731
spongedu Aug 10, 2018
9e9c581
Merge remote-tracking branch 'upstream/master' into dc_0731
spongedu Aug 10, 2018
a941ccf
Merge remote-tracking branch 'upstream/master' into dc_0731
spongedu Aug 10, 2018
927743f
Code fmt refine
spongedu Aug 10, 2018
6547c10
Merge branch 'master' into dc_0731
zz-jason Aug 10, 2018
7861596
Merge branch 'master' into dc_0731
zz-jason Aug 14, 2018
8e69463
Merge branch 'master' into dc_0731
zz-jason Aug 15, 2018
0a5eecc
Merge remote-tracking branch 'upstream/master' into dc_0731
spongedu Aug 15, 2018
cda9912
Add comments for test cases
spongedu Aug 15, 2018
d049d57
Merge branch 'dc_0731' of github.com:spongedu/tidb into dc_0731
spongedu Aug 15, 2018
c99eb2a
Merge branch 'master' into dc_0731
zhexuany Aug 16, 2018
c2cea53
Merge remote-tracking branch 'upstream/master' into dc_0731
spongedu Aug 16, 2018
af3effc
Code refine
spongedu Aug 16, 2018
4335cb1
Merge branch 'dc_0731' of github.com:spongedu/tidb into dc_0731
spongedu Aug 16, 2018
c36a4b9
Merge branch 'master' into dc_0731
zz-jason Aug 17, 2018
1a7996d
Merge branch 'master' into dc_0731
zz-jason Aug 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,138 @@ func (s *testSuite) TestValidateSetVar(c *C) {
result = tk.MustQuery("select @@time_zone;")
result.Check(testkit.Rows("SYSTEM"))

tk.MustExec("set @@global.max_connections=100001")
zz-jason marked this conversation as resolved.
Show resolved Hide resolved
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '100001'"))
result = tk.MustQuery("select @@global.max_connections;")
result.Check(testkit.Rows("100000"))

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

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

tk.MustExec("set @@global.max_connect_errors=18446744073709551615")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

tk.MustExec("set @@tmp_table_size=167772161")
result = tk.MustQuery("select @@tmp_table_size;")
result.Check(testkit.Rows("167772161"))

tk.MustExec("set @@tmp_table_size=18446744073709551615")
result = tk.MustQuery("select @@tmp_table_size;")
result.Check(testkit.Rows("18446744073709551615"))

_, err = tk.Exec("set @@tmp_table_size=18446744073709551616")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)

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

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

tk.MustExec("set @@global.connect_timeout=31536000")
result = tk.MustQuery("select @@global.connect_timeout;")
result.Check(testkit.Rows("31536000"))

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

result = tk.MustQuery("select @@sql_select_limit;")
result.Check(testkit.Rows("18446744073709551615"))
tk.MustExec("set @@sql_select_limit=default")
result = tk.MustQuery("select @@sql_select_limit;")
result.Check(testkit.Rows("18446744073709551615"))

tk.MustExec("set @@global.flush_time=31536001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect flush_time value: '31536001'"))

tk.MustExec("set @@global.interactive_timeout=31536001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect interactive_timeout value: '31536001'"))
}
20 changes: 15 additions & 5 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ var defaultSysVars = []*SysVar{
{ScopeSession, "rand_seed2", ""},
{ScopeGlobal, "validate_password_number_count", "1"},
{ScopeSession, "gtid_next", ""},
{ScopeGlobal | ScopeSession, "sql_select_limit", "18446744073709551615"},
{ScopeGlobal | ScopeSession, SQLSelectLimit, "18446744073709551615"},
{ScopeGlobal, "ndb_show_foreign_key_mock_tables", ""},
{ScopeNone, "multi_range_count", "256"},
{ScopeGlobal | ScopeSession, DefaultWeekFormat, "0"},
{ScopeGlobal | ScopeSession, "binlog_error_action", "IGNORE_ERROR"},
{ScopeGlobal, "slave_transaction_retries", "10"},
{ScopeGlobal | ScopeSession, "default_storage_engine", "InnoDB"},
{ScopeNone, "ft_query_expansion_limit", "20"},
{ScopeGlobal, "max_connect_errors", "100"},
{ScopeGlobal, MaxConnectErrors, "100"},
{ScopeGlobal, "sync_binlog", "0"},
{ScopeNone, "max_digest_length", "1024"},
{ScopeNone, "innodb_force_load_corrupted", "OFF"},
Expand All @@ -146,15 +146,15 @@ var defaultSysVars = []*SysVar{
{ScopeGlobal, "log_backward_compatible_user_definitions", ""},
{ScopeNone, "lc_messages_dir", "/usr/local/mysql-5.6.25-osx10.8-x86_64/share/"},
{ScopeGlobal, "ft_boolean_syntax", "+ -><()~*:\"\"&|"},
{ScopeGlobal, "table_definition_cache", "1400"},
{ScopeGlobal, TableDefinitionCache, "-1"},
{ScopeNone, SkipNameResolve, "0"},
{ScopeNone, "performance_schema_max_file_handles", "32768"},
{ScopeSession, "transaction_allow_batching", ""},
{ScopeGlobal | ScopeSession, SQLModeVar, mysql.DefaultSQLMode},
{ScopeNone, "performance_schema_max_statement_classes", "168"},
{ScopeGlobal, "server_id", "0"},
{ScopeGlobal, "innodb_flushing_avg_loops", "30"},
{ScopeGlobal | ScopeSession, "tmp_table_size", "16777216"},
{ScopeGlobal | ScopeSession, TmpTableSize, "16777216"},
{ScopeGlobal, "innodb_max_purge_lag", "0"},
{ScopeGlobal | ScopeSession, "preload_buffer_size", "32768"},
{ScopeGlobal, "slave_checkpoint_period", "300"},
Expand All @@ -163,7 +163,7 @@ var defaultSysVars = []*SysVar{
{ScopeGlobal, "innodb_flush_log_at_timeout", "1"},
{ScopeGlobal, "innodb_max_undo_log_size", ""},
{ScopeGlobal | ScopeSession, "range_alloc_block_size", "4096"},
{ScopeGlobal, "connect_timeout", "10"},
{ScopeGlobal, ConnectTimeout, "10"},
{ScopeGlobal | ScopeSession, "collation_server", charset.CollationUTF8},
{ScopeNone, "have_rtree_keys", "YES"},
{ScopeGlobal, "innodb_old_blocks_pct", "37"},
Expand Down Expand Up @@ -745,6 +745,16 @@ const (
WarningCount = "warning_count"
// ErrorCount is the name for 'error_count' system variable.
ErrorCount = "error_count"
// SQLSelectLimit is the name for 'sql_select_limit' system variable.
SQLSelectLimit = "sql_select_limit"
// MaxConnectErrors is the name for 'max_connect_errors' system variable.
MaxConnectErrors = "max_connect_errors"
// TableDefinitionCache is the name for 'table_definition_cache' system variable.
TableDefinitionCache = "table_definition_cache"
// TmpTableSize is the name for 'tmp_table_size' system variable.
TmpTableSize = "tmp_table_size"
// ConnectTimeout is the name for 'connect_timeout' system variable.
ConnectTimeout = "connect_timeout"
)

// GlobalVarAccessor is the interface for accessing global scope system and status variables.
Expand Down
Loading