diff options
author | unknown <anozdrin/alik@quad.opbmk> | 2008-03-18 13:51:17 +0300 |
---|---|---|
committer | unknown <anozdrin/alik@quad.opbmk> | 2008-03-18 13:51:17 +0300 |
commit | 07db330a55e54e59490b9e46faeade789a52d835 (patch) | |
tree | e96aaaaa6d8f3413c11e63aee2802003dfc5b2bc | |
parent | 269ebe54211cf96c4e64fa7268a1414588ca1de8 (diff) | |
parent | 809522598a9a8946a5e1fa4a981717c38466a379 (diff) | |
download | mariadb-git-07db330a55e54e59490b9e46faeade789a52d835.tar.gz |
Merge quad.opbmk:/mnt/raid/alik/MySQL/devel/5.1
into quad.opbmk:/mnt/raid/alik/MySQL/devel/5.1-rt-merged
libmysql/libmysql.c:
Auto merged
sql-common/client.c:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/mysqld.cc:
Auto merged
tests/mysql_client_test.c:
Auto merged
-rw-r--r-- | client/mysqltest.c | 2 | ||||
-rw-r--r-- | libmysql/libmysql.c | 17 | ||||
-rw-r--r-- | mysql-test/include/connect2.inc | 56 | ||||
-rw-r--r-- | mysql-test/r/connect.result | 103 | ||||
-rw-r--r-- | mysql-test/r/flush_read_lock_kill.result | 2 | ||||
-rw-r--r-- | mysql-test/r/kill.result | 2 | ||||
-rw-r--r-- | mysql-test/r/query_cache.result | 10 | ||||
-rw-r--r-- | mysql-test/r/sp_notembedded.result | 36 | ||||
-rw-r--r-- | mysql-test/r/trigger-trans.result | 19 | ||||
-rw-r--r-- | mysql-test/t/connect.test | 190 | ||||
-rw-r--r-- | mysql-test/t/flush_read_lock_kill.test | 5 | ||||
-rw-r--r-- | mysql-test/t/kill.test | 7 | ||||
-rw-r--r-- | mysql-test/t/query_cache.test | 9 | ||||
-rw-r--r-- | mysql-test/t/sp_notembedded.test | 141 | ||||
-rw-r--r-- | mysql-test/t/trigger-trans.test | 32 | ||||
-rw-r--r-- | sql-common/client.c | 28 | ||||
-rw-r--r-- | sql/mysql_priv.h | 5 | ||||
-rw-r--r-- | sql/mysqld.cc | 48 | ||||
-rw-r--r-- | sql/sql_cache.cc | 1 | ||||
-rw-r--r-- | sql/sql_class.cc | 22 | ||||
-rw-r--r-- | sql/sql_connect.cc | 13 | ||||
-rw-r--r-- | sql/sql_delete.cc | 14 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 4 | ||||
-rw-r--r-- | storage/ndb/src/kernel/blocks/tsman.cpp | 1 | ||||
-rw-r--r-- | tests/mysql_client_test.c | 25 |
25 files changed, 679 insertions, 113 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index 52e02789579..7ef184ae7e8 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -4221,11 +4221,13 @@ int connect_n_handle_errors(struct st_command *command, if (!mysql_real_connect(con, host, user, pass, db, port, sock ? sock: 0, CLIENT_MULTI_STATEMENTS)) { + var_set_errno(mysql_errno(con)); handle_error(command, mysql_errno(con), mysql_error(con), mysql_sqlstate(con), ds); return 0; /* Not connected */ } + var_set_errno(0); handle_no_error(command); return 1; /* Connected */ } diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 13ccd5749a3..15be5e34dff 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -2467,7 +2467,7 @@ static my_bool execute(MYSQL_STMT *stmt, char *packet, ulong length) int4store(buff+5, 1); /* iteration count */ res= test(cli_advanced_command(mysql, COM_STMT_EXECUTE, buff, sizeof(buff), - (uchar*) packet, length, 1, NULL) || + (uchar*) packet, length, 1, stmt) || (*mysql->methods->read_query_result)(mysql)); stmt->affected_rows= mysql->affected_rows; stmt->server_status= mysql->server_status; @@ -2683,7 +2683,7 @@ stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row) int4store(buff + 4, stmt->prefetch_rows); /* number of rows to fetch */ if ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH, buff, sizeof(buff), (uchar*) 0, 0, - 1, NULL)) + 1, stmt)) { set_stmt_errmsg(stmt, net); return 1; @@ -3350,7 +3350,7 @@ mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, */ if ((*mysql->methods->advanced_command)(mysql, COM_STMT_SEND_LONG_DATA, buff, sizeof(buff), (uchar*) data, - length, 1, NULL)) + length, 1, stmt)) { set_stmt_errmsg(stmt, &mysql->net); DBUG_RETURN(1); @@ -4748,6 +4748,13 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) MYSQL_DATA *result= &stmt->result; DBUG_ENTER("mysql_stmt_store_result"); + if (!mysql) + { + /* mysql can be reset in mysql_close called from mysql_reconnect */ + set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate, NULL); + DBUG_RETURN(1); + } + mysql= mysql->last_used_con; if (!stmt->field_count) @@ -4773,7 +4780,7 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) int4store(buff, stmt->stmt_id); int4store(buff + 4, (int)~0); /* number of rows to fetch */ if (cli_advanced_command(mysql, COM_STMT_FETCH, buff, sizeof(buff), - (uchar*) 0, 0, 1, NULL)) + (uchar*) 0, 0, 1, stmt)) { set_stmt_errmsg(stmt, net); DBUG_RETURN(1); @@ -4960,7 +4967,7 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags) uchar buff[MYSQL_STMT_HEADER]; /* packet header: 4 bytes for stmt id */ int4store(buff, stmt->stmt_id); if ((*mysql->methods->advanced_command)(mysql, COM_STMT_RESET, buff, - sizeof(buff), 0, 0, 0, NULL)) + sizeof(buff), 0, 0, 0, stmt)) { set_stmt_errmsg(stmt, &mysql->net); stmt->state= MYSQL_STMT_INIT_DONE; diff --git a/mysql-test/include/connect2.inc b/mysql-test/include/connect2.inc new file mode 100644 index 00000000000..6b830a909ed --- /dev/null +++ b/mysql-test/include/connect2.inc @@ -0,0 +1,56 @@ +# include/connect2.inc +# +# SUMMARY +# +# Make several attempts to connect. +# +# USAGE +# +# EXAMPLE +# +# connect.test +# + +--disable_query_log + +let $wait_counter= 300; +if ($wait_timeout) +{ + let $wait_counter= `SELECT $wait_timeout * 10`; +} +# Reset $wait_timeout so that its value won't be used on subsequent +# calls, and default will be used instead. +let $wait_timeout= 0; + +--echo # -- Establishing connection '$con_name' (user: $con_user_name)... + +while ($wait_counter) +{ + --disable_abort_on_error + --disable_result_log + --connect ($con_name,localhost,$con_user_name) + --enable_result_log + --enable_abort_on_error + + let $error = $mysql_errno; + + if (!$error) + { + let $wait_counter= 0; + } + if ($error) + { + real_sleep 0.1; + dec $wait_counter; + } +} +if ($error) +{ + --echo # -- Error: can not establish connection '$con_name'. +} +if (!$error) +{ + --echo # -- Connection '$con_name' has been established. +} + +--enable_query_log diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result index 25cf4f90e6d..727433d3032 100644 --- a/mysql-test/r/connect.result +++ b/mysql-test/r/connect.result @@ -115,3 +115,106 @@ create temporary table t2(id integer not null auto_increment primary key); set @id := 1; delete from t1 where id like @id; drop table t1; +# ------------------------------------------------------------------ +# -- End of 4.1 tests +# ------------------------------------------------------------------ + +# -- Bug#33507: Event scheduler creates more threads than max_connections +# -- which results in user lockout. + +GRANT USAGE ON *.* TO mysqltest_u1@localhost; + +SET GLOBAL max_connections = 3; +SET GLOBAL event_scheduler = ON; + +# -- Waiting for Event Scheduler to start... + +# -- Disconnecting default connection... + +# -- Check that we allow exactly three user connections, no matter how +# -- many threads are running. + +# -- Connecting (1)... +# -- Establishing connection 'con_1' (user: mysqltest_u1)... +# -- Connection 'con_1' has been established. + +# -- Connecting (2)... +# -- Establishing connection 'con_2' (user: mysqltest_u1)... +# -- Connection 'con_2' has been established. + +# -- Connecting (3)... +# -- Establishing connection 'con_3' (user: mysqltest_u1)... +# -- Connection 'con_3' has been established. + +# -- Connecting (4) [should fail]... +# -- Establishing connection 'con_4' (user: mysqltest_u1)... +# -- Error: can not establish connection 'con_4'. + +# -- Check that we allow one extra SUPER-user connection. + +# -- Connecting super (1)... +# -- Establishing connection 'con_super_1' (user: root)... +# -- Connection 'con_super_1' has been established. + +# -- Connecting super (2) [should fail]... +# -- Establishing connection 'con_super_2' (user: root)... +# -- Error: can not establish connection 'con_super_2'. + +# -- Ensure that we have Event Scheduler thread, 3 ordinary user +# -- connections and one extra super-user connection. +SELECT user FROM information_schema.processlist ORDER BY id; +user +event_scheduler +mysqltest_u1 +mysqltest_u1 +mysqltest_u1 +root + +# -- Resetting variables... +SET GLOBAL max_connections = 151; + +# -- Stopping Event Scheduler... +SET GLOBAL event_scheduler = OFF; + +# -- Waiting for Event Scheduler to stop... + +# -- That's it. Closing connections... + +# -- Restoring default connection... + +# -- Waiting for connections to close... + +DROP USER mysqltest_u1@localhost; + +# -- End of Bug#33507. + +# -- Bug#35074: max_used_connections is not correct. + +FLUSH STATUS; + +SHOW STATUS LIKE 'max_used_connections'; +Variable_name Value +Max_used_connections 1 + +# -- Starting Event Scheduler... +SET GLOBAL event_scheduler = ON; +# -- Waiting for Event Scheduler to start... + +# -- Opening a new connection to check max_used_connections... + +# -- Check that max_used_connections hasn't changed. +SHOW STATUS LIKE 'max_used_connections'; +Variable_name Value +Max_used_connections 2 + +# -- Closing new connection... + +# -- Stopping Event Scheduler... +SET GLOBAL event_scheduler = OFF; +# -- Waiting for Event Scheduler to stop... + +# -- End of Bug#35074. + +# ------------------------------------------------------------------ +# -- End of 5.1 tests +# ------------------------------------------------------------------ diff --git a/mysql-test/r/flush_read_lock_kill.result b/mysql-test/r/flush_read_lock_kill.result index f69656806da..0b599f343f7 100644 --- a/mysql-test/r/flush_read_lock_kill.result +++ b/mysql-test/r/flush_read_lock_kill.result @@ -1,3 +1,4 @@ +set @old_concurrent_insert= @@global.concurrent_insert; set @@global.concurrent_insert= 0; drop table if exists t1; create table t1 (kill_id int); @@ -8,3 +9,4 @@ select ((@id := kill_id) - kill_id) from t1; 0 kill connection @id; drop table t1; +set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result index a522d18f36b..8b6830d4798 100644 --- a/mysql-test/r/kill.result +++ b/mysql-test/r/kill.result @@ -1,3 +1,4 @@ +set @old_concurrent_insert= @@global.concurrent_insert; set @@global.concurrent_insert= 0; drop table if exists t1, t2, t3; create table t1 (kill_id int); @@ -137,3 +138,4 @@ KILL CONNECTION_ID(); # of close of the connection socket SELECT 1; Got one of the listed errors +set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index 1a728354c7b..ea42b6616a1 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -1650,6 +1650,16 @@ a (select count(*) from t2) 3 0 4 0 drop table t1,t2; +# +# Bug#25132 disabled query cache: Qcache_free_blocks = 1 +# +set global query_cache_size=100000; +set global query_cache_size=0; +set global query_cache_type=0; +show status like 'Qcache_free_blocks'; +Variable_name Value +Qcache_free_blocks 0 +Restore default values. set GLOBAL query_cache_type=default; set GLOBAL query_cache_limit=default; set GLOBAL query_cache_min_res_unit=default; diff --git a/mysql-test/r/sp_notembedded.result b/mysql-test/r/sp_notembedded.result index 0b1fa565d28..3efb01fdb94 100644 --- a/mysql-test/r/sp_notembedded.result +++ b/mysql-test/r/sp_notembedded.result @@ -1,3 +1,5 @@ +set @old_concurrent_insert= @@global.concurrent_insert; +set @@global.concurrent_insert= 0; drop table if exists t1,t3; drop procedure if exists bug4902| create procedure bug4902() @@ -17,11 +19,11 @@ begin show processlist; end| call bug4902_2()| -Id User Host db Command Time State Info -# root localhost test Query # NULL show processlist +show warnings| +Level Code Message call bug4902_2()| -Id User Host db Command Time State Info -# root localhost test Query # NULL show processlist +show warnings| +Level Code Message drop procedure bug4902_2| drop table if exists t1| create table t1 ( @@ -68,7 +70,7 @@ c 2 show status like 'Qcache_hits'| Variable_name Value -Qcache_hits 2 +Qcache_hits 0 set global query_cache_size = @x| flush status| flush query cache| @@ -208,3 +210,27 @@ GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION drop user mysqltest_1@localhost; drop procedure 15298_1; drop procedure 15298_2; +drop table if exists t1; +drop procedure if exists p1; +create table t1 (value varchar(15)); +create procedure p1() update t1 set value='updated' where value='old'; +call p1(); +insert into t1 (value) values ("old"); +select get_lock('b26162',120); +get_lock('b26162',120) +1 +select 'rl_acquirer', value from t1 where get_lock('b26162',120);; +set session low_priority_updates=on; +call p1();; +select 'rl_contender', value from t1; +rl_contender value +rl_contender old +select release_lock('b26162'); +release_lock('b26162') +1 +rl_acquirer value +rl_acquirer old +drop procedure p1; +drop table t1; +set session low_priority_updates=default; +set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/r/trigger-trans.result b/mysql-test/r/trigger-trans.result index cd5f629564f..dccaa27c5fd 100644 --- a/mysql-test/r/trigger-trans.result +++ b/mysql-test/r/trigger-trans.result @@ -140,4 +140,23 @@ select * from t3; c 1 drop table t1, t2, t3; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=innodb; +CREATE TABLE t2(b INT, FOREIGN KEY(b) REFERENCES t1(a)) ENGINE=innodb; +INSERT INTO t1 VALUES (1); +CREATE TRIGGER t1_bd BEFORE DELETE ON t1 FOR EACH ROW SET @a = 1; +CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW SET @b = 1; +SET @a = 0; +SET @b = 0; +TRUNCATE t1; +SELECT @a, @b; +@a @b +0 0 +INSERT INTO t1 VALUES (1); +DELETE FROM t1; +SELECT @a, @b; +@a @b +1 1 +DROP TABLE t2, t1; End of 5.0 tests diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 2e66c24d877..0893bf9ad18 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -102,4 +102,192 @@ disconnect con7; connection default; drop table t1; -# End of 4.1 tests +--disconnect con1 +--disconnect con2 +--disconnect con3 +--disconnect con4 +--disconnect con5 +--disconnect con6 +--disconnect con10 + +--echo # ------------------------------------------------------------------ +--echo # -- End of 4.1 tests +--echo # ------------------------------------------------------------------ + +########################################################################### + +--echo +--echo # -- Bug#33507: Event scheduler creates more threads than max_connections +--echo # -- which results in user lockout. + +--echo +GRANT USAGE ON *.* TO mysqltest_u1@localhost; + +# NOTE: if the test case fails sporadically due to spurious connections, +# consider disabling all users. + +--echo +let $saved_max_connections = `SELECT @@global.max_connections`; +SET GLOBAL max_connections = 3; +SET GLOBAL event_scheduler = ON; + +--echo +--echo # -- Waiting for Event Scheduler to start... +let $wait_condition = + SELECT COUNT(*) = 1 + FROM information_schema.processlist + WHERE user = 'event_scheduler'; +--source include/wait_condition.inc + +--echo +--echo # -- Disconnecting default connection... +--disconnect default + +--echo +--echo # -- Check that we allow exactly three user connections, no matter how +--echo # -- many threads are running. + +--echo +--echo # -- Connecting (1)... +let $con_name = con_1; +let $con_user_name = mysqltest_u1; +--source include/connect2.inc + +--echo +--echo # -- Connecting (2)... +let $con_name = con_2; +let $con_user_name = mysqltest_u1; +--source include/connect2.inc + +--echo +--echo # -- Connecting (3)... +let $con_name = con_3; +let $con_user_name = mysqltest_u1; +--source include/connect2.inc + +--echo +--echo # -- Connecting (4) [should fail]... +let $con_name = con_4; +let $con_user_name = mysqltest_u1; +let $wait_timeout = 5; +--source include/connect2.inc + +--echo +--echo # -- Check that we allow one extra SUPER-user connection. + +--echo +--echo # -- Connecting super (1)... +let $con_name = con_super_1; +let $con_user_name = root; +--source include/connect2.inc + +--echo +--echo # -- Connecting super (2) [should fail]... +let $con_name = con_super_2; +let $con_user_name = root; +let $wait_timeout = 5; +--source include/connect2.inc + +--echo +--echo # -- Ensure that we have Event Scheduler thread, 3 ordinary user +--echo # -- connections and one extra super-user connection. +SELECT user FROM information_schema.processlist ORDER BY id; + +--echo +--echo # -- Resetting variables... +--eval SET GLOBAL max_connections = $saved_max_connections + +--echo +--echo # -- Stopping Event Scheduler... +SET GLOBAL event_scheduler = OFF; + +--echo +--echo # -- Waiting for Event Scheduler to stop... +let $wait_condition = + SELECT COUNT(*) = 0 + FROM information_schema.processlist + WHERE user = 'event_scheduler'; +--source include/wait_condition.inc + +--echo +--echo # -- That's it. Closing connections... +--disconnect con_1 +--disconnect con_2 +--disconnect con_3 +--disconnect con_super_1 + +--echo +--echo # -- Restoring default connection... +--connect (default,localhost,root,,test) + +--echo +--echo # -- Waiting for connections to close... +let $wait_condition = + SELECT COUNT(*) = 1 + FROM information_schema.processlist + WHERE db = 'test'; +--source include/wait_condition.inc + +--echo +DROP USER mysqltest_u1@localhost; + +--echo +--echo # -- End of Bug#33507. +--echo + +########################################################################### + +--echo # -- Bug#35074: max_used_connections is not correct. +--echo + +FLUSH STATUS; + +--echo +SHOW STATUS LIKE 'max_used_connections'; + +--echo +--echo # -- Starting Event Scheduler... +SET GLOBAL event_scheduler = ON; + +--echo # -- Waiting for Event Scheduler to start... +let $wait_condition = + SELECT COUNT(*) = 1 + FROM information_schema.processlist + WHERE user = 'event_scheduler'; +--source include/wait_condition.inc + +# NOTE: We should use a new connection here instead of reconnect in order to +# avoid races (we can not for sure when the connection being disconnected is +# actually disconnected on the server). + +--echo +--echo # -- Opening a new connection to check max_used_connections... +--connect (con_1,localhost,root) + +--echo +--echo # -- Check that max_used_connections hasn't changed. +SHOW STATUS LIKE 'max_used_connections'; + +--echo +--echo # -- Closing new connection... +--disconnect con_1 +--connection default + +--echo +--echo # -- Stopping Event Scheduler... +SET GLOBAL event_scheduler = OFF; + +--echo # -- Waiting for Event Scheduler to stop... +let $wait_condition = + SELECT COUNT(*) = 0 + FROM information_schema.processlist + WHERE user = 'event_scheduler'; +--source include/wait_condition.inc + +--echo +--echo # -- End of Bug#35074. +--echo + +--echo # ------------------------------------------------------------------ +--echo # -- End of 5.1 tests +--echo # ------------------------------------------------------------------ diff --git a/mysql-test/t/flush_read_lock_kill.test b/mysql-test/t/flush_read_lock_kill.test index c3926d09205..c03f3be2534 100644 --- a/mysql-test/t/flush_read_lock_kill.test +++ b/mysql-test/t/flush_read_lock_kill.test @@ -14,6 +14,7 @@ # Disable concurrent inserts to avoid test failures when reading the # connection id which was inserted into a table by another thread. +set @old_concurrent_insert= @@global.concurrent_insert; set @@global.concurrent_insert= 0; connect (con1,localhost,root,,); @@ -58,3 +59,7 @@ reap; connection con2; drop table t1; +connection default; + +# Restore global concurrent_insert value +set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test index b7e1e82fe5d..8ef668f542b 100644 --- a/mysql-test/t/kill.test +++ b/mysql-test/t/kill.test @@ -8,6 +8,7 @@ # Disable concurrent inserts to avoid test failures when reading the # connection id which was inserted into a table by another thread. +set @old_concurrent_insert= @@global.concurrent_insert; set @@global.concurrent_insert= 0; connect (con1, localhost, root,,); @@ -326,3 +327,9 @@ KILL CONNECTION_ID(); --echo # of close of the connection socket --error 2013, 2006 SELECT 1; +--connection default + +########################################################################### + +# Restore global concurrent_insert value. Keep in the end of the test file. +set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index 771a32e8cd7..83fe1ab7d6e 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -1251,6 +1251,15 @@ disconnect user2; disconnect user3; # +--echo # +--echo # Bug#25132 disabled query cache: Qcache_free_blocks = 1 +--echo # +set global query_cache_size=100000; +set global query_cache_size=0; +set global query_cache_type=0; +show status like 'Qcache_free_blocks'; + +--echo Restore default values. # Bug #28211 RENAME DATABASE and query cache don't play nicely together # # TODO: enable these tests when RENAME DATABASE is implemented. diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test index 4e298b2076a..16ebb710f25 100644 --- a/mysql-test/t/sp_notembedded.test +++ b/mysql-test/t/sp_notembedded.test @@ -1,7 +1,9 @@ # Can't test with embedded server -- source include/not_embedded.inc +# Disable concurrent inserts to avoid test failures +set @old_concurrent_insert= @@global.concurrent_insert; +set @@global.concurrent_insert= 0; ---sleep 2 --disable_warnings drop table if exists t1,t3; --enable_warnings @@ -39,10 +41,14 @@ create procedure bug4902_2() begin show processlist; end| ---replace_column 1 # 6 # 3 localhost +--disable_result_log call bug4902_2()| ---replace_column 1 # 6 # 3 localhost +--enable_result_log +show warnings| +--disable_result_log call bug4902_2()| +--enable_result_log +show warnings| drop procedure bug4902_2| # @@ -268,69 +274,72 @@ drop procedure 15298_1; drop procedure 15298_2; # -# Test case disabled due to Bug#34891: sp_notembedded.test fails sporadically. +# Bug#29936 Stored Procedure DML ignores low_priority_updates setting # -# # -# # Bug#29936 Stored Procedure DML ignores low_priority_updates setting -# # -# -# --disable_warnings -# drop table if exists t1; -# drop procedure if exists p1; -# --enable_warnings -# -# create table t1 (value varchar(15)); -# create procedure p1() update t1 set value='updated' where value='old'; -# -# # load the procedure into sp cache and execute once -# call p1(); -# -# insert into t1 (value) values ("old"); -# -# connect (rl_holder, localhost, root,,); -# connect (rl_acquirer, localhost, root,,); -# connect (rl_contender, localhost, root,,); -# connect (rl_wait, localhost, root,,); -# -# connection rl_holder; -# select get_lock('b26162',120); -# -# connection rl_acquirer; -# --send select 'rl_acquirer', value from t1 where get_lock('b26162',120); -# -# # we must wait till this select opens and locks the tables -# connection rl_wait; -# let $wait_condition= -# select count(*) = 1 from information_schema.processlist -# where state = "User lock" and -# info = "select 'rl_acquirer', value from t1 where get_lock('b26162',120)"; -# --source include/wait_condition.inc -# -# connection default; -# set session low_priority_updates=on; -# --send call p1(); -# -# connection rl_wait; -# let $wait_condition= -# select count(*) = 1 from information_schema.processlist -# where state = "Locked" and -# info = "update t1 set value='updated' where value='old'"; -# --source include/wait_condition.inc -# -# connection rl_contender; -# select 'rl_contender', value from t1; -# -# connection rl_holder; -# select release_lock('b26162'); + +--disable_warnings +drop table if exists t1; +drop procedure if exists p1; +--enable_warnings + +create table t1 (value varchar(15)); +create procedure p1() update t1 set value='updated' where value='old'; + +# load the procedure into sp cache and execute once +call p1(); + +insert into t1 (value) values ("old"); + +connect (rl_holder, localhost, root,,); +connect (rl_acquirer, localhost, root,,); +connect (rl_contender, localhost, root,,); +connect (rl_wait, localhost, root,,); + +connection rl_holder; +select get_lock('b26162',120); + +connection rl_acquirer; +--send select 'rl_acquirer', value from t1 where get_lock('b26162',120); + +# we must wait till this select opens and locks the tables +connection rl_wait; +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "User lock" and + info = "select 'rl_acquirer', value from t1 where get_lock('b26162',120)"; +--source include/wait_condition.inc + +connection default; +set session low_priority_updates=on; +--send call p1(); + +connection rl_wait; +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Locked" and + info = "update t1 set value='updated' where value='old'"; +--source include/wait_condition.inc + +connection rl_contender; +select 'rl_contender', value from t1; + +connection rl_holder; +select release_lock('b26162'); + +connection rl_acquirer; +--reap +connection default; +--reap + +disconnect rl_holder; +disconnect rl_acquirer; +disconnect rl_wait; +drop procedure p1; +drop table t1; +set session low_priority_updates=default; + # -# connection rl_acquirer; -# --reap -# connection default; -# --reap +# Restore global concurrent_insert value. Keep in the end of the test file. # -# disconnect rl_holder; -# disconnect rl_acquirer; -# disconnect rl_wait; -# drop procedure p1; -# drop table t1; -# set session low_priority_updates=default; + +set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/t/trigger-trans.test b/mysql-test/t/trigger-trans.test index 8103a1ba0b1..5db5b982773 100644 --- a/mysql-test/t/trigger-trans.test +++ b/mysql-test/t/trigger-trans.test @@ -128,5 +128,37 @@ drop table t1, t2, t3; disconnect connection_update; disconnect connection_aux; +# +# Bug#34643: TRUNCATE crash if trigger and foreign key. +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings + +CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=innodb; +CREATE TABLE t2(b INT, FOREIGN KEY(b) REFERENCES t1(a)) ENGINE=innodb; + +INSERT INTO t1 VALUES (1); + +CREATE TRIGGER t1_bd BEFORE DELETE ON t1 FOR EACH ROW SET @a = 1; +CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW SET @b = 1; + +SET @a = 0; +SET @b = 0; + +TRUNCATE t1; + +SELECT @a, @b; + +INSERT INTO t1 VALUES (1); + +DELETE FROM t1; + +SELECT @a, @b; + +DROP TABLE t2, t1; + --echo End of 5.0 tests diff --git a/sql-common/client.c b/sql-common/client.c index 596c9f6c448..63c746a3f5a 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -695,6 +695,16 @@ cli_safe_read(MYSQL *mysql) strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); pos+= SQLSTATE_LENGTH+1; } + else + { + /* + The SQL state hasn't been received -- it should be reset to HY000 + (unknown error sql state). + */ + + strmov(net->sqlstate, unknown_sqlstate); + } + (void) strmake(net->last_error,(char*) pos, min((uint) len,(uint) sizeof(net->last_error)-1)); } @@ -733,11 +743,12 @@ my_bool cli_advanced_command(MYSQL *mysql, enum enum_server_command command, const uchar *header, ulong header_length, const uchar *arg, ulong arg_length, my_bool skip_check, - MYSQL_STMT *stmt __attribute__((unused))) + MYSQL_STMT *stmt) { NET *net= &mysql->net; my_bool result= 1; init_sigpipe_variables + my_bool stmt_skip= stmt ? stmt->state != MYSQL_STMT_INIT_DONE : FALSE; DBUG_ENTER("cli_advanced_command"); /* Don't give sigpipe errors if the client doesn't want them */ @@ -745,7 +756,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, if (mysql->net.vio == 0) { /* Do reconnect if possible */ - if (mysql_reconnect(mysql)) + if (mysql_reconnect(mysql) || stmt_skip) DBUG_RETURN(1); } if (mysql->status != MYSQL_STATUS_READY || @@ -777,7 +788,7 @@ cli_advanced_command(MYSQL *mysql, enum enum_server_command command, goto end; } end_server(mysql); - if (mysql_reconnect(mysql)) + if (mysql_reconnect(mysql) || stmt_skip) goto end; if (net_write_command(net,(uchar) command, header, header_length, arg, arg_length)) @@ -1911,7 +1922,13 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, (int) have_tcpip)); if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) goto error; - /* Try also with PIPE or TCP/IP */ + + /* + Try also with PIPE or TCP/IP. Clear the error from + create_shared_memory(). + */ + + net_clear_error(net); } else { @@ -2521,6 +2538,9 @@ my_bool mysql_reconnect(MYSQL *mysql) if (stmt->state != MYSQL_STMT_INIT_DONE) { stmt->mysql= 0; + stmt->last_errno= CR_SERVER_LOST; + strmov(stmt->last_error, ER(CR_SERVER_LOST)); + strmov(stmt->sqlstate, unknown_sqlstate); } else { diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 9bdf6e2a1d5..f035318c880 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -975,8 +975,6 @@ void time_out_user_resource_limits(THD *thd, USER_CONN *uc); void decrease_user_connections(USER_CONN *uc); void thd_init_client_charset(THD *thd, uint cs_number); bool setup_connection_thread_globals(THD *thd); -bool login_connection(THD *thd); -void end_connection(THD *thd); bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); @@ -1897,6 +1895,7 @@ extern bool opt_disable_networking, opt_skip_show_db; extern my_bool opt_character_set_client_handshake; extern bool volatile abort_loop, shutdown_in_progress; extern uint volatile thread_count, thread_running, global_read_lock; +extern uint connection_count; extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types; extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap; extern my_bool opt_slave_compressed_protocol, use_temp_pool; @@ -1935,7 +1934,7 @@ extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db, LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock, LOCK_global_system_variables, LOCK_user_conn, LOCK_prepared_stmt_count, - LOCK_bytes_sent, LOCK_bytes_received; + LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count; #ifdef HAVE_OPENSSL extern pthread_mutex_t LOCK_des_key_file; #endif diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d329c6798a7..16c65f48708 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -585,7 +585,8 @@ pthread_mutex_t LOCK_mysql_create_db, LOCK_Acl, LOCK_open, LOCK_thread_count, LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_bytes_sent, LOCK_bytes_received, LOCK_global_system_variables, - LOCK_user_conn, LOCK_slave_list, LOCK_active_mi; + LOCK_user_conn, LOCK_slave_list, LOCK_active_mi, + LOCK_connection_count; /** The below lock protects access to two global server variables: max_prepared_stmt_count and prepared_stmt_count. These variables @@ -721,6 +722,11 @@ char *des_key_file; struct st_VioSSLFd *ssl_acceptor_fd; #endif /* HAVE_OPENSSL */ +/** + Number of currently active user connections. The variable is protected by + LOCK_connection_count. +*/ +uint connection_count= 0; /* Function declarations */ @@ -1342,6 +1348,7 @@ static void clean_up_mutexes() (void) pthread_mutex_destroy(&LOCK_bytes_sent); (void) pthread_mutex_destroy(&LOCK_bytes_received); (void) pthread_mutex_destroy(&LOCK_user_conn); + (void) pthread_mutex_destroy(&LOCK_connection_count); Events::destroy_mutexes(); #ifdef HAVE_OPENSSL (void) pthread_mutex_destroy(&LOCK_des_key_file); @@ -1784,6 +1791,11 @@ void unlink_thd(THD *thd) DBUG_ENTER("unlink_thd"); DBUG_PRINT("enter", ("thd: 0x%lx", (long) thd)); thd->cleanup(); + + pthread_mutex_lock(&LOCK_connection_count); + --connection_count; + pthread_mutex_unlock(&LOCK_connection_count); + (void) pthread_mutex_lock(&LOCK_thread_count); thread_count--; delete thd; @@ -3452,6 +3464,7 @@ static int init_thread_environment() (void) pthread_mutex_init(&LOCK_global_read_lock, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_prepared_stmt_count, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST); + (void) pthread_mutex_init(&LOCK_connection_count, MY_MUTEX_INIT_FAST); #ifdef HAVE_OPENSSL (void) pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); #ifndef HAVE_YASSL @@ -4699,6 +4712,11 @@ void create_thread_to_handle_connection(THD *thd) thread_count--; thd->killed= THD::KILL_CONNECTION; // Safety (void) pthread_mutex_unlock(&LOCK_thread_count); + + pthread_mutex_lock(&LOCK_connection_count); + --connection_count; + pthread_mutex_unlock(&LOCK_connection_count); + statistic_increment(aborted_connects,&LOCK_status); /* Can't use my_error() since store_globals has not been called. */ my_snprintf(error_message_buff, sizeof(error_message_buff), @@ -4738,15 +4756,34 @@ static void create_new_thread(THD *thd) if (protocol_version > 9) net->return_errno=1; - /* don't allow too many connections */ - if (thread_count - delayed_insert_threads >= max_connections+1 || abort_loop) + /* + Don't allow too many connections. We roughly check here that we allow + only (max_connections + 1) connections. + */ + + pthread_mutex_lock(&LOCK_connection_count); + + if (connection_count >= max_connections + 1 || abort_loop) { + pthread_mutex_unlock(&LOCK_connection_count); + DBUG_PRINT("error",("Too many connections")); close_connection(thd, ER_CON_COUNT_ERROR, 1); delete thd; DBUG_VOID_RETURN; } + + ++connection_count; + + if (connection_count > max_used_connections) + max_used_connections= connection_count; + + pthread_mutex_unlock(&LOCK_connection_count); + + /* Start a new thread to handle connection. */ + pthread_mutex_lock(&LOCK_thread_count); + /* The initialization of thread_id is done in create_embedded_thd() for the embedded library. @@ -4754,13 +4791,10 @@ static void create_new_thread(THD *thd) */ thd->thread_id= thd->variables.pseudo_thread_id= thread_id++; - /* Start a new thread to handle connection */ thread_count++; - if (thread_count - delayed_insert_threads > max_used_connections) - max_used_connections= thread_count - delayed_insert_threads; - thread_scheduler.add_connection(thd); + DBUG_VOID_RETURN; } #endif /* EMBEDDED_LIBRARY */ diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index ae6765c7934..388700f0efa 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1998,6 +1998,7 @@ void Query_cache::make_disabled() query_cache_size= 0; queries_blocks= 0; free_memory= 0; + free_memory_blocks= 0; bins= 0; steps= 0; cache= 0; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 376102c8bf9..594577dd89c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -395,8 +395,11 @@ Diagnostics_area::set_ok_status(THD *thd, ha_rows affected_rows_arg, { DBUG_ASSERT(! is_set()); #ifdef DBUG_OFF - /* In production, refuse to overwrite an error with an OK packet. */ - if (is_error()) + /* + In production, refuse to overwrite an error or a custom response + with an OK packet. + */ + if (is_error() || is_disabled()) return; #endif /** Only allowed to report success if has not yet reported an error */ @@ -424,8 +427,11 @@ Diagnostics_area::set_eof_status(THD *thd) DBUG_ASSERT(! is_set()); #ifdef DBUG_OFF - /* In production, refuse to overwrite an error with an EOF packet. */ - if (is_error()) + /* + In production, refuse to overwrite an error or a custom response + with an EOF packet. + */ + if (is_error() || is_disabled()) return; #endif @@ -454,6 +460,14 @@ Diagnostics_area::set_error_status(THD *thd, uint sql_errno_arg, an error can happen during the flush. */ DBUG_ASSERT(! is_set() || can_overwrite_status); +#ifdef DBUG_OFF + /* + In production, refuse to overwrite a custom response with an + ERROR packet. + */ + if (is_disabled()) + return; +#endif m_sql_errno= sql_errno_arg; strmake(m_message, message_arg, sizeof(m_message) - 1); diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index b22a33e3e92..6f8cd6494cd 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -402,10 +402,11 @@ check_user(THD *thd, enum enum_server_command command, if (check_count) { - VOID(pthread_mutex_lock(&LOCK_thread_count)); - bool count_ok= thread_count <= max_connections + delayed_insert_threads - || (thd->main_security_ctx.master_access & SUPER_ACL); - VOID(pthread_mutex_unlock(&LOCK_thread_count)); + pthread_mutex_lock(&LOCK_connection_count); + bool count_ok= connection_count <= max_connections || + (thd->main_security_ctx.master_access & SUPER_ACL); + VOID(pthread_mutex_unlock(&LOCK_connection_count)); + if (!count_ok) { // too many connections my_error(ER_CON_COUNT_ERROR, MYF(0)); @@ -930,7 +931,7 @@ bool setup_connection_thread_globals(THD *thd) */ -bool login_connection(THD *thd) +static bool login_connection(THD *thd) { NET *net= &thd->net; int error; @@ -968,7 +969,7 @@ bool login_connection(THD *thd) This mainly updates status variables */ -void end_connection(THD *thd) +static void end_connection(THD *thd) { NET *net= &thd->net; plugin_thdvar_cleanup(thd); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 990f7713561..b9a7cd12662 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -45,6 +45,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, bool transactional_table, safe_update, const_cond; bool const_cond_result; ha_rows deleted= 0; + bool triggers_applicable; uint usable_index= MAX_KEY; SELECT_LEX *select_lex= &thd->lex->select_lex; THD::killed_state killed_status= THD::NOT_KILLED; @@ -102,6 +103,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, /* Error evaluating val_int(). */ DBUG_RETURN(TRUE); } + /* Test if the user wants to delete all rows and deletion doesn't have any side-effects (because of triggers), so we can use optimized @@ -249,7 +251,13 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, init_ftfuncs(thd, select_lex, 1); thd_proc_info(thd, "updating"); - if (table->triggers && + + /* NOTE: TRUNCATE must not invoke triggers. */ + + triggers_applicable= table->triggers && + thd->lex->sql_command != SQLCOM_TRUNCATE; + + if (triggers_applicable && table->triggers->has_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER)) { @@ -274,7 +282,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (!(select && select->skip_record())&& ! thd->is_error() ) { - if (table->triggers && + if (triggers_applicable && table->triggers->process_triggers(thd, TRG_EVENT_DELETE, TRG_ACTION_BEFORE, FALSE)) { @@ -285,7 +293,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (!(error= table->file->ha_delete_row(table->record[0]))) { deleted++; - if (table->triggers && + if (triggers_applicable && table->triggers->process_triggers(thd, TRG_EVENT_DELETE, TRG_ACTION_AFTER, FALSE)) { diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index a027ffe9daa..c922b21af90 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2555,6 +2555,8 @@ void mysql_stmt_close(THD *thd, char *packet) Prepared_statement *stmt; DBUG_ENTER("mysql_stmt_close"); + thd->main_da.disable_status(); + if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_close"))) DBUG_VOID_RETURN; @@ -2566,8 +2568,6 @@ void mysql_stmt_close(THD *thd, char *packet) (void) stmt->deallocate(); general_log_print(thd, thd->command, NullS); - thd->main_da.disable_status(); - DBUG_VOID_RETURN; } diff --git a/storage/ndb/src/kernel/blocks/tsman.cpp b/storage/ndb/src/kernel/blocks/tsman.cpp index 8e68e118f98..ce5797cf209 100644 --- a/storage/ndb/src/kernel/blocks/tsman.cpp +++ b/storage/ndb/src/kernel/blocks/tsman.cpp @@ -181,7 +181,6 @@ struct TsmanChunk Vector<Uint32> bitmask; }; template class Vector<TsmanChunk>; -template class Vector<Uint32>; #endif void diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 73f47825ae9..a50d9d74aaf 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -12016,6 +12016,7 @@ static void test_bug5194() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); + mysql_stmt_reset(stmt); } mysql_stmt_close(stmt); @@ -16610,6 +16611,11 @@ static void test_bug27592() DBUG_VOID_RETURN; } + +/** + Bug#29948 autoreconnect + prepared statements + kill seems unstable +*/ + static void test_bug29948() { MYSQL *dbc=NULL; @@ -16622,7 +16628,10 @@ static void test_bug29948() const char *query; int buf; unsigned long length, cursor_type; - + + DBUG_ENTER("test_bug29948"); + myheader("test_bug29948"); + dbc = mysql_init(NULL); DIE_UNLESS(dbc); @@ -16658,7 +16667,7 @@ static void test_bug29948() res= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void *)&cursor_type); myquery(res); - query= "SELECT * from t1 where a=?"; + query= "SELECT * FROM t1 WHERE a=?"; res= mysql_stmt_prepare(stmt, query, strlen(query)); myquery(res); @@ -16670,16 +16679,20 @@ static void test_bug29948() res= mysql_stmt_bind_result(stmt,&bind); check_execute(stmt, res); - - sprintf(kill_buf, "kill %ld", dbc->thread_id); - mysql_query(dbc, kill_buf); + + my_snprintf(kill_buf, sizeof(kill_buf), "KILL %ld", dbc->thread_id); + res= mysql_query(dbc, kill_buf); + myquery(res); res= mysql_stmt_store_result(stmt); DIE_UNLESS(res); mysql_stmt_free_result(stmt); mysql_stmt_close(stmt); - mysql_query(dbc, "DROP TABLE t1"); + + res= mysql_query(dbc, "DROP TABLE t1"); + myquery(res); + mysql_close(dbc); } |