include/master-slave.inc
Warnings:
Note	####	Sending passwords in plain text without SSL/TLS is extremely insecure.
Note	####	Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
[connection master]
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
SET @@session.binlog_direct_non_transactional_updates= FALSE;
DROP DATABASE IF EXISTS db1;
DROP DATABASE IF EXISTS db2;
CREATE DATABASE db1;
CREATE DATABASE db2;
use db1;
CREATE TABLE db1.t1 (a INT) ENGINE=InnoDB;
CREATE TABLE db1.t2 (s CHAR(255)) ENGINE=MyISAM;
include/sync_slave_sql_with_master.inc
include/stop_slave.inc
[on master]
CREATE PROCEDURE db1.p1 ()
BEGIN
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
INSERT INTO t1 VALUES (3);
INSERT INTO t1 VALUES (4);
INSERT INTO t1 VALUES (5);
END//
CREATE PROCEDURE db1.p2 ()
BEGIN
INSERT INTO t1 VALUES (6);
INSERT INTO t1 VALUES (7);
INSERT INTO t1 VALUES (8);
INSERT INTO t1 VALUES (9);
INSERT INTO t1 VALUES (10);
INSERT INTO t2 VALUES ('executed db1.p2()');
END//
INSERT INTO db1.t2 VALUES ('before call db1.p1()');
use test;
BEGIN;
CALL db1.p1();
COMMIT;
INSERT INTO db1.t2 VALUES ('after call db1.p1()');
SELECT * FROM db1.t1;
a
1
2
3
4
5
SELECT * FROM db1.t2;
s
before call db1.p1()
after call db1.p1()
[on slave]
start slave until master_log_file='master-bin.000001', master_log_pos=MASTER_POS;
include/wait_for_slave_sql_to_stop.inc
#
# If we got non-zero here, then we're suffering BUG#43263
#
SELECT 0 as 'Must be 0';
Must be 0
0
SELECT * from db1.t1;
a
1
2
3
4
5
SELECT * from db1.t2;
s
before call db1.p1()
[on master]
INSERT INTO db1.t2 VALUES ('before call db1.p2()');
BEGIN;
CALL db1.p2();
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
ROLLBACK;
INSERT INTO db1.t2 VALUES ('after call db1.p2()');
SELECT * FROM db1.t1;
a
1
2
3
4
5
SELECT * FROM db1.t2;
s
before call db1.p1()
after call db1.p1()
before call db1.p2()
executed db1.p2()
after call db1.p2()
[on slave]
start slave until master_log_file='master-bin.000001', master_log_pos=MASTER_POS;
include/wait_for_slave_sql_to_stop.inc
#
# If we got non-zero here, then we're suffering BUG#43263
#
SELECT 0 as 'Must be 0';
Must be 0
0
SELECT * from db1.t1;
a
1
2
3
4
5
SELECT * from db1.t2;
s
before call db1.p1()
executed db1.p2()
START SLAVE;
include/wait_for_slave_sql_to_start.inc
#
# SAVEPOINT and ROLLBACK TO have the same problem in BUG#43263
# This was reported by BUG#50407
[on master]
SET SESSION AUTOCOMMIT=0
BEGIN;
INSERT INTO db1.t1 VALUES(20);
# 
# Verify whether this statement is binlogged correctly
/*comment*/ SAVEPOINT has_comment;
USE db1;
INSERT INTO db1.t1 VALUES(30);
INSERT INTO db1.t2 VALUES("in savepoint has_comment");
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
USE db2;
SavePoint mixed_cases;
USE db1;
INSERT INTO db1.t2 VALUES("in savepoint mixed_cases");
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
INSERT INTO db1.t1 VALUES(40);
USE db2;
ROLLBACK TO mixed_cases;
Warnings:
Warning	1196	Some non-transactional changed tables couldn't be rolled back
ROLLBACK TO has_comment;
Warnings:
Warning	1196	Some non-transactional changed tables couldn't be rolled back
USE db1;
INSERT INTO db1.t2 VALUES("after rollback to");
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
INSERT INTO db1.t1 VALUES(50);
USE db2;
COMMIT;
include/show_binlog_events.inc
Log_name	Pos	Event_type	Server_id	End_log_pos	Info
master-bin.000001	#	Query	#	#	BEGIN
master-bin.000001	#	Query	#	#	use `test`; INSERT INTO db1.t1 VALUES(20)
master-bin.000001	#	Query	#	#	SAVEPOINT `has_comment`
master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t1 VALUES(30)
master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t2 VALUES("in savepoint has_comment")
master-bin.000001	#	Query	#	#	SAVEPOINT `mixed_cases`
master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t2 VALUES("in savepoint mixed_cases")
master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t1 VALUES(40)
master-bin.000001	#	Query	#	#	ROLLBACK TO `mixed_cases`
master-bin.000001	#	Query	#	#	ROLLBACK TO `has_comment`
master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t2 VALUES("after rollback to")
master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO db1.t1 VALUES(50)
master-bin.000001	#	Xid	#	#	COMMIT /* XID */
include/sync_slave_sql_with_master.inc
[on slave]
#
# Verify INSERT statements in savepoints are executed, for MyISAM table
# is not effected by ROLLBACK TO
SELECT * FROM db1.t2 WHERE s LIKE '% savepoint %';
s
in savepoint has_comment
in savepoint mixed_cases
#
# Verify INSERT statements on the Innodb table are rolled back;
SELECT * FROM db1.t1 WHERE a IN (30, 40);
a

# BUG#55798 Slave SQL retry on transaction inserts extra data into
# non-transaction table
# ----------------------------------------------------------------
# To verify that SQL thread does not retry a transaction which can
# not be rolled back safely, even though only a temporary error is
# encountered.

# [ on master ]
USE db1;
DROP TABLE t1, t2;
CREATE TABLE t1(c1 INT KEY, c2 CHAR(100)) ENGINE=InnoDB;
CREATE TABLE t2(c1 INT) ENGINE=MyISAM;
CREATE TABLE t3(c1 INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES(1, "master");
SET @@session.binlog_direct_non_transactional_updates= FALSE;
include/sync_slave_sql_with_master.inc
# [ on slave ]
USE db1;
SET @timeout_old= @@GLOBAL.innodb_lock_wait_timeout;
SET GLOBAL innodb_lock_wait_timeout= 1;
STOP SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_stop.inc
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc
# Verify the SQL thread doesn't retry the transaction when one of
# its statements has modified a non-transactional table.
# ----------------------------------------------------------------

# INSERT statement inserts a row to a non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
INSERT INTO t2 VALUES(1);
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
UPDATE t1 SET c2='INSERT INTO t2 VALUES(1)' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# INSERT ... SELECT statement inserts a row to a non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
INSERT INTO t2 SELECT 2;
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
UPDATE t1 SET c2='INSERT INTO t2 SELECT 2' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# UPDATE statement updates a row to a non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
UPDATE t2 SET c1= 3;
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
UPDATE t1 SET c2='UPDATE t2 SET c1= 3' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# MULTI-UPDATE statement updates a row to a non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
UPDATE t2, t3 SET t2.c1=4, t3.c1= 4;
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them.
UPDATE t1 SET c2='UPDATE t2, t3 SET t2.c1=4, t3.c1= 4' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# DELETE statement deletes a row from a non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
DELETE FROM t2;
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it accesses a non-transactional table after accessing a transactional table within the same transaction.
UPDATE t1 SET c2='DELETE FROM t2' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# CREATE TEMPORARY TABLE statement in the transaction
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
CREATE TEMPORARY TABLE IF NOT EXISTS temp_t(c1 INT);
UPDATE t1 SET c2='CREATE TEMPORARY TABLE IF NOT EXISTS temp_t(c1 INT)' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# DROP TEMPORARY TABLE statement in the transaction
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
DROP TEMPORARY TABLE IF EXISTS temp_t;
UPDATE t1 SET c2='DROP TEMPORARY TABLE IF EXISTS temp_t' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# Verify that the SQL thread doesn't retry the transaction if one
# of the sub-statements has modified a non-transactional table.
# ----------------------------------------------------------------
CREATE FUNCTION f_insert()
RETURNS INT
BEGIN
INSERT INTO t2 VALUES(1);
RETURN 2;
END|
CREATE FUNCTION f_insert_select()
RETURNS INT
BEGIN
INSERT INTO t2 SELECT 2;
RETURN 2;
END|
CREATE FUNCTION f_update()
RETURNS INT
BEGIN
UPDATE t2 SET c1=3;
RETURN 2;
END |
CREATE TABLE t4 (c1 INT) |
INSERT INTO t4 VAlUES(1),(2) |
CREATE FUNCTION f_multi_update()
RETURNS INT
BEGIN
UPDATE t2, t4 SET t2.c1=4, t4.c1= 4;
RETURN 2;
END |
CREATE FUNCTION f_delete()
RETURNS INT
BEGIN
DELETE FROM t2;
RETURN 2;
END |

# The INSERT statement in a function inserts a row into a
# non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
INSERT INTO t3 VALUES(f_insert());
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them.
UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_insert())' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# The INSERT ... SELECT statement in a function inserts a row into a
# non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
INSERT INTO t3 VALUES(f_insert());
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them.
UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_insert())' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# The UPDATE statement in a function updates a row of a
# non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
INSERT INTO t3 VALUES(f_update());
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them.
UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_update())' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# The MULTI-UPDATE statement in a function updates a row of a
# non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
INSERT INTO t3 VALUES(f_multi_update());
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them.
UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_multi_update())' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc

# The DELETE statement in a function deletes a row from a
# non-transactional table.
# [ on slave ]
BEGIN;
# It will lock table t1 on the row in which c1 is 1 until COMMIT or ROLLBACK
UPDATE t1 SET c2= "slave" WHERE c1= 1;
# [ on master ]
BEGIN;
INSERT INTO t3 VALUES(1);
INSERT INTO t3 VALUES(f_delete());
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them.
UPDATE t1 SET c2='INSERT INTO t3 VALUES(f_delete())' WHERE c1= 1;
COMMIT;
# [ on slave ]
include/wait_for_slave_sql_error.inc [errno=1205]
ROLLBACK;
START SLAVE SQL_THREAD;
include/wait_for_slave_sql_to_start.inc
SET @@global.innodb_lock_wait_timeout= @timeout_old;
#
# Clean up
#
DROP DATABASE db1;
DROP DATABASE db2;
include/rpl_end.inc
