summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2015-01-27 13:13:55 +0530
committerNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2015-01-27 13:13:55 +0530
commitaa1de7372846e3a37c87b7488d34426264d7da44 (patch)
tree0949f08132016a052d7340f46093e771c1e31580 /mysql-test
parent7a408dbdf40930144c1bad654cb1e31e5ce5fc7a (diff)
downloadmariadb-git-aa1de7372846e3a37c87b7488d34426264d7da44.tar.gz
Bug#20094067: BACKPORT BUG#19683834 TO 5.5 AND 5.6
Backporting the patch and the test case fixed as part of BUG#16041903 and BUG#19683834 respectively.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/sp.result108
-rw-r--r--mysql-test/r/trigger-trans.result25
-rw-r--r--mysql-test/t/sp.test118
-rw-r--r--mysql-test/t/trigger-trans.test54
4 files changed, 305 insertions, 0 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 10350708e44..4d93ce202fe 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -7809,3 +7809,111 @@ Warnings:
Error 1424 Recursive stored functions and triggers are not allowed.
Error 1305 FUNCTION test.f1 does not exist
DROP FUNCTION f1;
+
+#
+# BUG 16041903: CONTINUE HANDLER NOT INVOKED
+# IN A STORED FUNCTION AFTER A LOCK WAIT TIMEOUT
+#
+
+# Save and set lock wait timeout
+SET @lock_wait_timeout_saved= @@lock_wait_timeout;
+SET @innodb_lock_wait_timeout_saved= @@innodb_lock_wait_timeout;
+SET @@lock_wait_timeout= 1;
+SET @@innodb_lock_wait_timeout= 1;
+
+# Create a function with exit handler:
+CREATE FUNCTION f1() RETURNS VARCHAR(20)
+BEGIN
+DECLARE EXIT HANDLER FOR SQLSTATE '42S02' RETURN 'No such table';
+INSERT INTO no_such_table VALUES (1);
+END//
+
+# Create a function calling f1():
+CREATE FUNCTION f2() RETURNS VARCHAR(20)
+BEGIN
+RETURN f1();
+END//
+
+# Create a function provoking deadlock:
+CREATE FUNCTION f3() RETURNS VARCHAR(20)
+BEGIN
+UPDATE t1 SET i= 1 WHERE i= 1;
+RETURN 'Will never get here';
+END//
+
+# Create a function calling f3, to create
+# a deadlock indirectly:
+CREATE FUNCTION f4() RETURNS VARCHAR(20)
+BEGIN
+RETURN f3();
+END//
+
+# Open another connection, create and initialize a table
+# to be used for provoking deadlock, put a lock on the table:
+CREATE TABLE t1 (i INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+SET AUTOCOMMIT= 0;
+UPDATE t1 SET i=1 WHERE i=1;
+
+# On the default connection, do an update to provoke a
+# deadlock, then call the function with handler. This case
+# fails without the patch (with error ER_NO_SUCH_TABLE):
+SET AUTOCOMMIT= 0;
+UPDATE t1 SET i=1 WHERE i=1;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT f1() AS 'f1():';
+f1():
+No such table
+Warnings:
+Error 1146 Table 'test.no_such_table' doesn't exist
+
+# Provoke another deadlock, then call the function with
+# handler indirectly. This case fails without the patch
+# (with error ER_NO_SUCH_TABLE):
+UPDATE t1 SET i= 1 WHERE i= 1;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT f2() AS 'f2():';
+f2():
+No such table
+Warnings:
+Error 1146 Table 'test.no_such_table' doesn't exist
+
+# Provoke yet another deadlock, but now from within a function,
+# then call the function with handler. This succeeds even
+# without the patch because is_fatal_sub_stmt_error is reset
+# in restore_sub_stmt after the failing function has been
+# executed. The test case is included anyway for better coverage:
+SELECT f3() AS 'f3():';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT f1() AS 'f1():';
+f1():
+No such table
+Warnings:
+Error 1146 Table 'test.no_such_table' doesn't exist
+# Provoke yet another deadlock, but now from within a function,
+# calling another function, then call the function with handler.
+# This succeeds even without the patch because
+# is_fatal_sub_stmt_error is reset in restore_sub_stmt after
+# the failing function has been executed. The test case is
+# included anyway for better coverage:
+SELECT f4() AS 'f4():';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT f1() AS 'f1():';
+f1():
+No such table
+Warnings:
+Error 1146 Table 'test.no_such_table' doesn't exist
+
+# Disconnect, drop functions and table:
+DROP FUNCTION f4;
+DROP FUNCTION f3;
+DROP FUNCTION f2;
+DROP FUNCTION f1;
+DROP TABLE t1;
+
+# Reset lock wait timeouts
+SET @@lock_wait_timeout= @lock_wait_timeout_saved;
+SET @@innodb_lock_wait_timeout= @innodb_lock_wait_timeout_saved;
+#
+# BUG 16041903: End of test case
+#
diff --git a/mysql-test/r/trigger-trans.result b/mysql-test/r/trigger-trans.result
index 722ac79854d..cab7336cbe5 100644
--- a/mysql-test/r/trigger-trans.result
+++ b/mysql-test/r/trigger-trans.result
@@ -195,3 +195,28 @@ b val
14 g
drop trigger t1_after_insert;
drop table t1,t2;
+#
+#Bug#19683834 SOME INNODB ERRORS CAUSES STORED FUNCTION
+# AND TRIGGER HANDLERS TO BE IGNORED
+#Code fixed in Bug#16041903
+CREATE TABLE t1 (id int unsigned PRIMARY KEY, val int DEFAULT 0)
+ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (1), (2);
+CREATE TABLE t2 (id int PRIMARY KEY);
+CREATE TABLE t3 LIKE t2;
+CREATE TRIGGER bef_insert BEFORE INSERT ON t2 FOR EACH ROW
+BEGIN
+DECLARE CONTINUE HANDLER FOR 1062 BEGIN END;
+INSERT INTO t3 (id) VALUES (NEW.id);
+INSERT INTO t3 (id) VALUES (NEW.id);
+END//
+START TRANSACTION;
+UPDATE t1 SET val = val + 1;
+connect con2,localhost,root,,test,,;
+SET SESSION innodb_lock_wait_timeout = 2;
+UPDATE t1 SET val = val + 1;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t2 (id) VALUES (1);
+disconnect con2;
+connection default;
+DROP TABLE t3, t2, t1;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index a17c61917fc..5e02ca55081 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -15,6 +15,9 @@
# Tests that require multibyte character sets, which are not always available,
# go into separate files (e.g. sp-ucs2.test)
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
use test;
# Test tables
@@ -9093,3 +9096,118 @@ delimiter ;$
SELECT f1();
DROP FUNCTION f1;
+
+
+--echo
+--echo #
+--echo # BUG 16041903: CONTINUE HANDLER NOT INVOKED
+--echo # IN A STORED FUNCTION AFTER A LOCK WAIT TIMEOUT
+--echo #
+
+--echo
+--echo # Save and set lock wait timeout
+SET @lock_wait_timeout_saved= @@lock_wait_timeout;
+SET @innodb_lock_wait_timeout_saved= @@innodb_lock_wait_timeout;
+SET @@lock_wait_timeout= 1;
+SET @@innodb_lock_wait_timeout= 1;
+
+--echo
+--echo # Create a function with exit handler:
+DELIMITER //;
+CREATE FUNCTION f1() RETURNS VARCHAR(20)
+BEGIN
+ DECLARE EXIT HANDLER FOR SQLSTATE '42S02' RETURN 'No such table';
+ INSERT INTO no_such_table VALUES (1);
+END//
+
+--echo
+--echo # Create a function calling f1():
+CREATE FUNCTION f2() RETURNS VARCHAR(20)
+BEGIN
+ RETURN f1();
+END//
+
+--echo
+--echo # Create a function provoking deadlock:
+CREATE FUNCTION f3() RETURNS VARCHAR(20)
+BEGIN
+ UPDATE t1 SET i= 1 WHERE i= 1;
+ RETURN 'Will never get here';
+END//
+
+--echo
+--echo # Create a function calling f3, to create
+--echo # a deadlock indirectly:
+CREATE FUNCTION f4() RETURNS VARCHAR(20)
+BEGIN
+ RETURN f3();
+END//
+DELIMITER ;//
+
+--echo
+--echo # Open another connection, create and initialize a table
+--echo # to be used for provoking deadlock, put a lock on the table:
+connect (con1,localhost,root,,);
+CREATE TABLE t1 (i INT) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+SET AUTOCOMMIT= 0;
+UPDATE t1 SET i=1 WHERE i=1;
+
+--echo
+--echo # On the default connection, do an update to provoke a
+--echo # deadlock, then call the function with handler. This case
+--echo # fails without the patch (with error ER_NO_SUCH_TABLE):
+--connection default
+SET AUTOCOMMIT= 0;
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t1 SET i=1 WHERE i=1;
+SELECT f1() AS 'f1():';
+
+--echo
+--echo # Provoke another deadlock, then call the function with
+--echo # handler indirectly. This case fails without the patch
+--echo # (with error ER_NO_SUCH_TABLE):
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t1 SET i= 1 WHERE i= 1;
+SELECT f2() AS 'f2():';
+
+--echo
+--echo # Provoke yet another deadlock, but now from within a function,
+--echo # then call the function with handler. This succeeds even
+--echo # without the patch because is_fatal_sub_stmt_error is reset
+--echo # in restore_sub_stmt after the failing function has been
+--echo # executed. The test case is included anyway for better coverage:
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT f3() AS 'f3():';
+SELECT f1() AS 'f1():';
+
+--echo # Provoke yet another deadlock, but now from within a function,
+--echo # calling another function, then call the function with handler.
+--echo # This succeeds even without the patch because
+--echo # is_fatal_sub_stmt_error is reset in restore_sub_stmt after
+--echo # the failing function has been executed. The test case is
+--echo # included anyway for better coverage:
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT f4() AS 'f4():';
+SELECT f1() AS 'f1():';
+
+--echo
+--echo # Disconnect, drop functions and table:
+--disconnect con1
+DROP FUNCTION f4;
+DROP FUNCTION f3;
+DROP FUNCTION f2;
+DROP FUNCTION f1;
+DROP TABLE t1;
+
+--echo
+--echo # Reset lock wait timeouts
+SET @@lock_wait_timeout= @lock_wait_timeout_saved;
+SET @@innodb_lock_wait_timeout= @innodb_lock_wait_timeout_saved;
+
+--echo #
+--echo # BUG 16041903: End of test case
+--echo #
+
+# Wait till we reached the initial number of concurrent sessions
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/t/trigger-trans.test b/mysql-test/t/trigger-trans.test
index 82bee7aa224..c17202055e1 100644
--- a/mysql-test/t/trigger-trans.test
+++ b/mysql-test/t/trigger-trans.test
@@ -2,6 +2,9 @@
# (or just InnoDB storage engine)
--source include/have_innodb.inc
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
--disable_warnings
drop table if exists t1;
--enable_warnings
@@ -182,3 +185,54 @@ insert into t1 values ( 654, 'a'), ( 654, 'b'), ( 654, 'c'),
select * from t2 order by b;
drop trigger t1_after_insert;
drop table t1,t2;
+
+--echo #
+--echo #Bug#19683834 SOME INNODB ERRORS CAUSES STORED FUNCTION
+--echo # AND TRIGGER HANDLERS TO BE IGNORED
+
+--echo #Code fixed in Bug#16041903
+--enable_connect_log
+
+CREATE TABLE t1 (id int unsigned PRIMARY KEY, val int DEFAULT 0)
+ENGINE=InnoDB;
+INSERT INTO t1 (id) VALUES (1), (2);
+
+CREATE TABLE t2 (id int PRIMARY KEY);
+CREATE TABLE t3 LIKE t2;
+
+# Trigger with continue handler for ER_DUP_ENTRY(1062)
+DELIMITER //;
+CREATE TRIGGER bef_insert BEFORE INSERT ON t2 FOR EACH ROW
+BEGIN
+ DECLARE CONTINUE HANDLER FOR 1062 BEGIN END;
+ INSERT INTO t3 (id) VALUES (NEW.id);
+ INSERT INTO t3 (id) VALUES (NEW.id);
+END//
+DELIMITER ;//
+
+# Transaction 1: Grab locks on t1
+START TRANSACTION;
+UPDATE t1 SET val = val + 1;
+
+# Transaction 2:
+--connect (con2,localhost,root,,test,,)
+SET SESSION innodb_lock_wait_timeout = 2;
+# Trigger lock timeout (1205)
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t1 SET val = val + 1;
+
+# This insert should go through, as the continue handler should
+# handle ER_DUP_ENTRY, even after ER_LOCK_WAIT_TIMEOUT (Bug#16041903)
+INSERT INTO t2 (id) VALUES (1);
+
+# Cleanup
+disconnect con2;
+--source include/wait_until_disconnected.inc
+connection default;
+
+DROP TABLE t3, t2, t1;
+
+--disable_connect_log
+
+# Wait till we reached the initial number of concurrent sessions
+--source include/wait_until_count_sessions.inc