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

server: use max_allowed_packet to limit the packet size. (#33651) #34053

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrDelayedCantChangeLock: mysql.Message("Delayed insert thread couldn't get requested lock for table %-.192s", nil),
ErrTooManyDelayedThreads: mysql.Message("Too many delayed threads in use", nil),
ErrAbortingConnection: mysql.Message("Aborted connection %d to db: '%-.192s' user: '%-.48s' (%-.64s)", nil),
ErrNetPacketTooLarge: mysql.Message("Got a packet bigger than 'maxAllowedPacket' bytes", nil),
ErrNetPacketTooLarge: mysql.Message("Got a packet bigger than 'max_allowed_packet' bytes", nil),
ErrNetReadErrorFromPipe: mysql.Message("Got a read error from the connection pipe", nil),
ErrNetFcntl: mysql.Message("Got an error from fcntl()", nil),
ErrNetPacketsOutOfOrder: mysql.Message("Got packets out of order", nil),
Expand Down
114 changes: 114 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,120 @@ func (s *testSerialSuite1) TestSetVar(c *C) {
tk.MustExec(`set tidb_enable_ordered_result_mode=1`)
tk.MustQuery(`select @@global.tidb_enable_ordered_result_mode`).Check(testkit.Rows("0"))
tk.MustQuery(`select @@tidb_enable_ordered_result_mode`).Check(testkit.Rows("1"))
<<<<<<< HEAD
=======

// test for tidb_opt_enable_correlation_adjustment
tk.MustQuery(`select @@tidb_opt_enable_correlation_adjustment`).Check(testkit.Rows("1"))
tk.MustExec(`set global tidb_opt_enable_correlation_adjustment = 0`)
tk.MustQuery(`select @@global.tidb_opt_enable_correlation_adjustment`).Check(testkit.Rows("0"))
tk.MustExec(`set global tidb_opt_enable_correlation_adjustment = 1`)
tk.MustQuery(`select @@global.tidb_opt_enable_correlation_adjustment`).Check(testkit.Rows("1"))
tk.MustExec(`set tidb_opt_enable_correlation_adjustment=0`)
tk.MustQuery(`select @@global.tidb_opt_enable_correlation_adjustment`).Check(testkit.Rows("1"))
tk.MustQuery(`select @@tidb_opt_enable_correlation_adjustment`).Check(testkit.Rows("0"))

// test for tidb_opt_limit_push_down_threshold
tk.MustQuery(`select @@tidb_opt_limit_push_down_threshold`).Check(testkit.Rows("100"))
tk.MustExec(`set global tidb_opt_limit_push_down_threshold = 20`)
tk.MustQuery(`select @@global.tidb_opt_limit_push_down_threshold`).Check(testkit.Rows("20"))
tk.MustExec(`set global tidb_opt_limit_push_down_threshold = 100`)
tk.MustQuery(`select @@global.tidb_opt_limit_push_down_threshold`).Check(testkit.Rows("100"))
tk.MustExec(`set tidb_opt_limit_push_down_threshold = 20`)
tk.MustQuery(`select @@global.tidb_opt_limit_push_down_threshold`).Check(testkit.Rows("100"))
tk.MustQuery(`select @@tidb_opt_limit_push_down_threshold`).Check(testkit.Rows("20"))

tk.MustQuery("select @@tidb_opt_prefer_range_scan").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_opt_prefer_range_scan = 1")
tk.MustQuery("select @@global.tidb_opt_prefer_range_scan").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_opt_prefer_range_scan = 0")
tk.MustQuery("select @@global.tidb_opt_prefer_range_scan").Check(testkit.Rows("0"))
tk.MustExec("set session tidb_opt_prefer_range_scan = 1")
tk.MustQuery("select @@session.tidb_opt_prefer_range_scan").Check(testkit.Rows("1"))
tk.MustExec("set session tidb_opt_prefer_range_scan = 0")
tk.MustQuery("select @@session.tidb_opt_prefer_range_scan").Check(testkit.Rows("0"))

tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = 0.5")
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("0.5"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = 1")
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = 1.5")
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("1.5"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = 10")
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("10"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = -1")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_tso_client_batch_max_wait_time value: '-1'"))
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = -0.01")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_tso_client_batch_max_wait_time value: '-0.01'"))
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = 10.01")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_tso_client_batch_max_wait_time value: '10.01'"))
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("10"))
tk.MustExec("set global tidb_tso_client_batch_max_wait_time = 10.1")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_tso_client_batch_max_wait_time value: '10.1'"))
tk.MustQuery("select @@tidb_tso_client_batch_max_wait_time").Check(testkit.Rows("10"))
require.Error(t, tk.ExecToErr("set tidb_tso_client_batch_max_wait_time = 1"))

tk.MustQuery("select @@tidb_enable_tso_follower_proxy").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_enable_tso_follower_proxy = 1")
tk.MustQuery("select @@tidb_enable_tso_follower_proxy").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_enable_tso_follower_proxy = 0")
tk.MustQuery("select @@tidb_enable_tso_follower_proxy").Check(testkit.Rows("0"))
require.Error(t, tk.ExecToErr("set tidb_enable_tso_follower_proxy = 1"))

tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_enable_historical_stats = 1")
tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_enable_historical_stats = 0")
tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("0"))

// test for tidb_enable_column_tracking
tk.MustQuery("select @@tidb_enable_column_tracking").Check(testkit.Rows("0"))
tk.MustExec("set global tidb_enable_column_tracking = 1")
tk.MustQuery("select @@tidb_enable_column_tracking").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_enable_column_tracking = 0")
tk.MustQuery("select @@tidb_enable_column_tracking").Check(testkit.Rows("0"))
// When set tidb_enable_column_tracking off, we record the time of the setting operation.
tk.MustQuery("select count(1) from mysql.tidb where variable_name = 'tidb_disable_column_tracking_time' and variable_value is not null").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_enable_column_tracking = 1")
tk.MustQuery("select @@tidb_enable_column_tracking").Check(testkit.Rows("1"))
require.Error(t, tk.ExecToErr("select @@session.tidb_enable_column_tracking"))
require.Error(t, tk.ExecToErr("set tidb_enable_column_tracking = 0"))
require.Error(t, tk.ExecToErr("set global tidb_enable_column_tracking = -1"))

// test for tidb_ignore_prepared_cache_close_stmt
tk.MustQuery("select @@global.tidb_ignore_prepared_cache_close_stmt").Check(testkit.Rows("0")) // default value is 0
tk.MustExec("set global tidb_ignore_prepared_cache_close_stmt=1")
tk.MustQuery("select @@global.tidb_ignore_prepared_cache_close_stmt").Check(testkit.Rows("1"))
tk.MustQuery("show global variables like 'tidb_ignore_prepared_cache_close_stmt'").Check(testkit.Rows("tidb_ignore_prepared_cache_close_stmt ON"))
tk.MustExec("set global tidb_ignore_prepared_cache_close_stmt=0")
tk.MustQuery("select @@global.tidb_ignore_prepared_cache_close_stmt").Check(testkit.Rows("0"))
tk.MustQuery("show global variables like 'tidb_ignore_prepared_cache_close_stmt'").Check(testkit.Rows("tidb_ignore_prepared_cache_close_stmt OFF"))

// test for tidb_remove_orderby_in_subquery
tk.MustQuery("select @@session.tidb_remove_orderby_in_subquery").Check(testkit.Rows("0")) // default value is 0
tk.MustExec("set session tidb_remove_orderby_in_subquery=1")
tk.MustQuery("select @@session.tidb_remove_orderby_in_subquery").Check(testkit.Rows("1"))
tk.MustQuery("select @@global.tidb_remove_orderby_in_subquery").Check(testkit.Rows("0")) // default value is 0
tk.MustExec("set global tidb_remove_orderby_in_subquery=1")
tk.MustQuery("select @@global.tidb_remove_orderby_in_subquery").Check(testkit.Rows("1"))

// the value of max_allowed_packet should be a multiple of 1024
tk.MustExec("set @@global.max_allowed_packet=16385")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect max_allowed_packet value: '16385'"))
result := tk.MustQuery("select @@global.max_allowed_packet;")
result.Check(testkit.Rows("16384"))
tk.MustExec("set @@max_allowed_packet=2047")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect max_allowed_packet value: '2047'"))
result = tk.MustQuery("select @@max_allowed_packet;")
result.Check(testkit.Rows("1024"))
tk.MustExec("set @@global.max_allowed_packet=0")
tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect max_allowed_packet value: '0'"))
result = tk.MustQuery("select @@global.max_allowed_packet;")
result.Check(testkit.Rows("1024"))
>>>>>>> 4d3a3c259... server: use max_allowed_packet to limit the packet size. (#33651)
}

func (s *testSuite5) TestTruncateIncorrectIntSessionVar(c *C) {
Expand Down
Loading