From 7555c16adf2597958cb1295e3a46b6cef7cfccf0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Oct 2007 13:25:00 -0400 Subject: [PATCH 1/6] Merge bk-internal.mysql.com:/home/bk/mysql-5.1-runtime into damien-katzs-computer.local:/Users/dkatz/mysql-5.1-runtime BitKeeper/deleted/.del-.del-changelog: Delete: BitKeeper/deleted/.del-changelog From c6e00be97f62ebcf9c10727ea637d57dc368dead Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Oct 2007 15:16:43 -0400 Subject: [PATCH 2/6] Bug #31332 --event-scheduler option misbehaving Changed the behaviour of the --event-scheduler option when used without an arguments. It now turns the option on. mysql-test/r/events_bugs.result: Test that --event-scheduler with no options in events_bugs-master.opt turns the option on. mysql-test/t/events_bugs.test: Test that --event-scheduler with no options in events_bugs-master.opt turns the option on. sql/events.cc: Changed the behaviour of the --event-scheduler option when used without an arguments. It now turns the option on. mysql-test/t/events_bugs-master.opt: Test that --event-scheduler with no options in events_bugs-master.opt turns the option on. --- mysql-test/r/events_bugs.result | 4 ++++ mysql-test/t/events_bugs-master.opt | 1 + mysql-test/t/events_bugs.test | 15 +++++++++++++++ sql/events.cc | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 mysql-test/t/events_bugs-master.opt diff --git a/mysql-test/r/events_bugs.result b/mysql-test/r/events_bugs.result index b6b77101874..b0de2358777 100644 --- a/mysql-test/r/events_bugs.result +++ b/mysql-test/r/events_bugs.result @@ -3,6 +3,10 @@ drop database if exists mysqltest_db1; drop database if exists mysqltest_db2; create database events_test; use events_test; +select * from information_schema.global_variables where variable_name like 'event_scheduler'; +VARIABLE_NAME VARIABLE_VALUE +EVENT_SCHEDULER ON +SET GLOBAL event_scheduler = 'OFF'; CREATE EVENT lower_case ON SCHEDULE EVERY 1 MINUTE DO SELECT 1; CREATE EVENT Lower_case ON SCHEDULE EVERY 2 MINUTE DO SELECT 2; ERROR HY000: Event 'Lower_case' already exists diff --git a/mysql-test/t/events_bugs-master.opt b/mysql-test/t/events_bugs-master.opt new file mode 100644 index 00000000000..f93413a61e5 --- /dev/null +++ b/mysql-test/t/events_bugs-master.opt @@ -0,0 +1 @@ +--event-scheduler diff --git a/mysql-test/t/events_bugs.test b/mysql-test/t/events_bugs.test index ebd86f3a3d2..efdb67349ec 100644 --- a/mysql-test/t/events_bugs.test +++ b/mysql-test/t/events_bugs.test @@ -9,6 +9,21 @@ drop database if exists mysqltest_db2; create database events_test; use events_test; +# +# START: Bug #31332 --event-scheduler option misbehaving +# + +# NOTE!! this test must come first! It's testing that the --event-scheduler +# option with no argument in events_bugs-master.opt turns the scheduler on. + +select * from information_schema.global_variables where variable_name like 'event_scheduler'; + +SET GLOBAL event_scheduler = 'OFF'; + +# +# END: Bug #31332 +# + # # START - 16415: Events: event names are case sensitive # diff --git a/sql/events.cc b/sql/events.cc index 1bfbc5d6645..67249b40c79 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -146,7 +146,7 @@ bool Events::set_opt_event_scheduler(char *argument) { if (argument == NULL) - opt_event_scheduler= Events::EVENTS_DISABLED; + opt_event_scheduler= Events::EVENTS_ON; else { int type; From 819eaead10f656356dbc8f41770679b5ed45a8c9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Nov 2007 14:44:17 +0300 Subject: [PATCH 3/6] Fix for a BUG#31898: 16M memory allocations for user variables in stored procedure. The problem was that MySQL used unnecessarily large amounts of memory if user variables were used as an argument to CONCAT or CONCAT_WS -- 16M per each user variable used. Technically, it happened because MySQL used the following allocation strategy for string functions to avoid multiple realloc() calls: in the virtual operation fix_length_and_dec() the attribute max_length was calculated as a sum of max_length values for each argument. Although this approach worked well for small (or fixed) data types, there could be a problem if there as a user variable among the arguments of a string function -- max_length of the function would be 16M (as the max_length of a user variable is 16M). Both CONCAT() and CONCAT_WS() functions suffer from this problem. The fix is to do not use meta-data for allocating memory. The following strategy is proposed instead: allocate the exact length of the result string at the first record, double the amount of memory allocated when it is required. No test case for this bug because there is no way to test memory consumption in a robust way with our test suite. sql/item_strfunc.cc: Implement memory-wise allocation strategy. --- sql/item_strfunc.cc | 60 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 03c65c9d654..a7624c5bbcd 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -356,10 +356,35 @@ String *Item_func_concat::val_str(String *str) } else { // Two big const strings - if (tmp_value.alloc(max_length) || - tmp_value.copy(*res) || - tmp_value.append(*res2)) + /* + NOTE: We should be prudent in the initial allocation unit -- the + size of the arguments is a function of data distribution, which + can be any. Instead of overcommitting at the first row, we grow + the allocated amount by the factor of 2. This ensures that no + more than 25% of memory will be overcommitted on average. + */ + + uint concat_len= res->length() + res2->length(); + + if (tmp_value.alloced_length() < concat_len) + { + if (tmp_value.alloced_length() == 0) + { + if (tmp_value.alloc(concat_len)) + goto null; + } + else + { + uint new_len = max(tmp_value.alloced_length() * 2, concat_len); + + if (tmp_value.realloc(new_len)) + goto null; + } + } + + if (tmp_value.copy(*res) || tmp_value.append(*res2)) goto null; + res= &tmp_value; use_as_buff=str; } @@ -679,8 +704,33 @@ String *Item_func_concat_ws::val_str(String *str) } else { // Two big const strings - if (tmp_value.alloc(max_length) || - tmp_value.copy(*res) || + /* + NOTE: We should be prudent in the initial allocation unit -- the + size of the arguments is a function of data distribution, which can + be any. Instead of overcommitting at the first row, we grow the + allocated amount by the factor of 2. This ensures that no more than + 25% of memory will be overcommitted on average. + */ + + uint concat_len= res->length() + sep_str->length() + res2->length(); + + if (tmp_value.alloced_length() < concat_len) + { + if (tmp_value.alloced_length() == 0) + { + if (tmp_value.alloc(concat_len)) + goto null; + } + else + { + uint new_len = max(tmp_value.alloced_length() * 2, concat_len); + + if (tmp_value.realloc(new_len)) + goto null; + } + } + + if (tmp_value.copy(*res) || tmp_value.append(*sep_str) || tmp_value.append(*res2)) goto null; From 0dda7aa6db995cdfb3ce86bcc21ae496d3414f5a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Nov 2007 17:26:32 +0300 Subject: [PATCH 4/6] A patch for BUG#32172: information_schema test fails with wait_condition timeout. The problem was that the event thread didn't manage to execute the event in 30 seconds on highly-loaded box. The fix is to increase timeout. This is a fix for the test suite. mysql-test/t/information_schema.test: Provide more time to execute an event. --- mysql-test/t/information_schema.test | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 1987d9d5773..55334916913 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1142,6 +1142,7 @@ END$$ DELIMITER ;$$ +let $wait_timeout= 300; let $wait_condition=select count(*) = 0 from information_schema.events where event_name='event_status'; --source include/wait_condition.inc From 8c3048e9da7473fea1d2ca4276245724d6197673 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 14 Nov 2007 16:12:46 -0500 Subject: [PATCH 5/6] Bug#28785 thread-handling not displayed properly in SHOW VARIABLES mysql-test/r/no-threads.result: Test that we are in the 'no-threads' thread_handling mode. mysql-test/t/no-threads.test: Test that we are in the 'no-threads' thread_handling mode. sql/mysqld.cc: Changes to make global_system_variables.thread_handling be zero based, instead of 1 based. sql/scheduler.h: Changed the enum to start at 0, to match the array elements in thread_handling_names in mysqld.cc --- mysql-test/r/no-threads.result | 3 +++ mysql-test/t/no-threads.test | 1 + sql/mysqld.cc | 5 +++-- sql/scheduler.h | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/no-threads.result b/mysql-test/r/no-threads.result index 50e52138be8..aefecd0f7bc 100644 --- a/mysql-test/r/no-threads.result +++ b/mysql-test/r/no-threads.result @@ -4,3 +4,6 @@ select 1+1; select 1+2; 1+2 3 +SHOW GLOBAL VARIABLES LIKE 'thread_handling'; +Variable_name Value +thread_handling no-threads diff --git a/mysql-test/t/no-threads.test b/mysql-test/t/no-threads.test index 806cf24e961..31ea6406ee9 100644 --- a/mysql-test/t/no-threads.test +++ b/mysql-test/t/no-threads.test @@ -3,3 +3,4 @@ # select 1+1; select 1+2; +SHOW GLOBAL VARIABLES LIKE 'thread_handling'; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4cf6e05751f..f65fee872ed 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7745,12 +7745,13 @@ mysqld_get_one_option(int optid, break; } case OPT_ONE_THREAD: - global_system_variables.thread_handling= 2; + global_system_variables.thread_handling= + SCHEDULER_ONE_THREAD_PER_CONNECTION; break; case OPT_THREAD_HANDLING: { global_system_variables.thread_handling= - find_type_or_exit(argument, &thread_handling_typelib, opt->name); + find_type_or_exit(argument, &thread_handling_typelib, opt->name)-1; break; } case OPT_FT_BOOLEAN_SYNTAX: diff --git a/sql/scheduler.h b/sql/scheduler.h index 8351cefda4c..46bbd300cbb 100644 --- a/sql/scheduler.h +++ b/sql/scheduler.h @@ -40,7 +40,7 @@ public: enum scheduler_types { - SCHEDULER_ONE_THREAD_PER_CONNECTION=1, + SCHEDULER_ONE_THREAD_PER_CONNECTION=0, SCHEDULER_NO_THREADS, SCHEDULER_POOL_OF_THREADS }; From 91f001398654238fb98d7c82e1be18e11ef53138 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Nov 2007 15:35:35 +0300 Subject: [PATCH 6/6] A patch for BUG#19723: kill of active connection yields different error code depending on platform. On Mac OS X, KILL statement issued to kill the current connection would return a different error code and message than on other platforms ('MySQL server has gone away' instead of 'Shutdown in progress'). The reason for this difference was that on Mac OS X we have macro SIGNAL_WITH_VIO_CLOSE defined. This macro forces KILL implementation to close the communication socket of the thread that is being killed. SIGNAL_WITH_VIO_CLOSE macro is defined on platforms where just sending a signal is not a reliable mechanism to interrupt the thread from sleeping on a blocking system call. In a nutshell, closing the socket is a hack to work around an operating system bug and awake the blocked thread no matter what. However, if the thread that is being killed is the same thread that issued KILL statement, closing the socket leads to a prematurely lost connection. At the same time it is not necessary to close the socket in this case, since the thread in question is not inside a blocking system call. The fix, therefore, is to not close the socket if the thread that is being killed is the same that issued KILL statement, even with defined SIGNAL_WITH_VIO_CLOSE. mysql-test/r/kill.result: Update result file. mysql-test/t/kill.test: Added a test case for BUG#19723: kill of active connection yields different error code depending on platform. sql/sql_class.cc: Call close_active_vio() only if we're killing another thread. --- mysql-test/r/kill.result | 9 +++++++++ mysql-test/t/kill.test | 16 ++++++++++++++++ sql/sql_class.cc | 15 ++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result index a08be429a83..8376eb7c0de 100644 --- a/mysql-test/r/kill.result +++ b/mysql-test/r/kill.result @@ -125,3 +125,12 @@ drop function bug27563; drop procedure proc27563; PREPARE stmt FROM 'EXPLAIN SELECT * FROM t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40 WHERE a1=a2 AND a2=a3 AND a3=a4 AND a4=a5 AND a5=a6 AND a6=a7 AND a7=a8 AND a8=a9 AND a9=a10 AND a10=a11 AND a11=a12 AND a12=a13 AND a13=a14 AND a14=a15 AND a15=a16 AND a16=a17 AND a17=a18 AND a18=a19 AND a19=a20 AND a20=a21 AND a21=a22 AND a22=a23 AND a23=a24 AND a24=a25 AND a25=a26 AND a26=a27 AND a27=a28 AND a28=a29 AND a29=a30 AND a30=a31 AND a31=a32 AND a32=a33 AND a33=a34 AND a34=a35 AND a35=a36 AND a36=a37 AND a37=a38 AND a38=a39 AND a39=a40 '; EXECUTE stmt; +# +# Bug#19723: kill of active connection yields different error code +# depending on platform. +# + +# Connection: con2. +KILL CONNECTION_ID(); +SELECT 1; +ERROR HY000: Lost connection to MySQL server during query diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test index 5d5095f7d61..219412e5afa 100644 --- a/mysql-test/t/kill.test +++ b/mysql-test/t/kill.test @@ -304,3 +304,19 @@ while ($i) dec $i ; } --enable_query_log + +########################################################################### + +--echo # +--echo # Bug#19723: kill of active connection yields different error code +--echo # depending on platform. +--echo # + +--echo +--echo # Connection: con2. +--connection con2 + +KILL CONNECTION_ID(); + +--error 2013 +SELECT 1; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a904023cbff..368ed897a4d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -818,7 +818,20 @@ void THD::awake(THD::killed_state state_to_set) if (!slave_thread) thread_scheduler.post_kill_notification(this); #ifdef SIGNAL_WITH_VIO_CLOSE - close_active_vio(); + if (this != current_thd) + { + /* + In addition to a signal, let's close the socket of the thread that + is being killed. This is to make sure it does not block if the + signal is lost. This needs to be done only on platforms where + signals are not a reliable interruption mechanism. + + If we're killing ourselves, we know that we're not blocked, so this + hack is not used. + */ + + close_active_vio(); + } #endif } if (mysys_var)