mirror of
https://github.com/MariaDB/server.git
synced 2025-12-01 17:39:21 +03:00
MDEV-21810 MBR: Unexpected "Unsafe statement" warning for unsafe IODKU
MDEV-17614 fixes to replication unsafety for INSERT ON DUP KEY UPDATE
on two or more unique key table left a flaw. The fixes checked the
safety condition per each inserted record with the idea to catch a user-created
value to an autoincrement column and when that succeeds the autoincrement column
would become the source of unsafety too.
It was not expected that after a duplicate error the next record's
write_set may become different and the unsafe decision for that
specific record will be computed to screw the Query's binlogging
state and when @@binlog_format is MIXED nothing gets bin-logged.
This case has been already fixed in 10.5.2 by 91ab42a823 that
relocated/optimized THD::decide_logging_format_low() out of the record insert
loop. The safety decision is computed once and at the right time.
Pertinent parts of the commit are cherry-picked.
Also a spurious warning about unsafety is removed when MIXED
@@binlog_format; original MDEV-17614 test result corrected.
The original test of MDEV-17614 is extended and made more readable.
173 lines
5.1 KiB
Plaintext
173 lines
5.1 KiB
Plaintext
source include/have_debug.inc;
|
|
source include/have_innodb.inc;
|
|
-- source include/have_binlog_format_statement.inc
|
|
source include/master-slave.inc;
|
|
# MDEV-17614 INSERT on dup key update is replication unsafe
|
|
#
|
|
# The following cases are tested below:
|
|
# 1. 2 unique key, replication is UNSAFE
|
|
# 2. 2 unique key, with one auto increment key and implicit value to it.
|
|
# It is UNSAFE because autoinc column values of being inserted records
|
|
# are revealed dynamically, so unknown at the binlog-format decision time
|
|
# and hence this pessimistic expectation
|
|
# 3. 2 unique keys
|
|
# A. insert is only in 1 unique key, still all colums are specified => UNSAFE
|
|
# B. both unique keys are specified => UNSAFE
|
|
# C. only one unique key is specified => SAFE (motivated by MDEV-28310)
|
|
# 4. 2 unique key, with one auto increment key(but user gives auto inc value) =>
|
|
# UNSAFE to replicate
|
|
|
|
--echo # Case 1: UNSAFE
|
|
call mtr.add_suppression("Unsafe statement written to the binary log using statement format");
|
|
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY , b INT,
|
|
UNIQUE(b), c int) engine=innodb;
|
|
sync_slave_with_master;
|
|
connection master;
|
|
INSERT INTO t1 VALUES (1, 1, 1);
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master1
|
|
INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
--connection slave
|
|
# show the error message
|
|
--let $slave_sql_errno= 1062
|
|
--let $show_slave_sql_error= 1
|
|
--source include/wait_for_slave_sql_error.inc
|
|
--echo #Different value from server
|
|
SELECT * FROM t1;
|
|
|
|
# restart replication for the next testcase
|
|
stop slave;
|
|
--source include/wait_for_slave_to_stop.inc
|
|
reset slave;
|
|
connection master;
|
|
reset master;
|
|
drop table t1;
|
|
connection slave;
|
|
start slave;
|
|
--source include/wait_for_slave_to_start.inc
|
|
|
|
--echo # Case 2: UNSAFE
|
|
--connection master
|
|
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT,
|
|
UNIQUE(b), c int) engine=innodb;
|
|
sync_slave_with_master;
|
|
connection master;
|
|
INSERT INTO t1 VALUES (default, 1, 1);
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES (default, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master1
|
|
INSERT INTO t1 VALUES(default, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
--sync_slave_with_master
|
|
--echo #same data as master
|
|
SELECT * FROM t1;
|
|
|
|
connection master;
|
|
drop table t1;
|
|
--sync_slave_with_master
|
|
|
|
--echo # Case 3A: UNSAFE
|
|
--connection master
|
|
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT,
|
|
UNIQUE(b), c int, d int ) engine=innodb;
|
|
sync_slave_with_master;
|
|
connection master;
|
|
INSERT INTO t1 VALUES (1, 1, 1, 1);
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES (2, NULL, 2, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master1
|
|
INSERT INTO t1 VALUES(3, NULL, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
--sync_slave_with_master
|
|
--echo #same data as master
|
|
SELECT * FROM t1;
|
|
connection master;
|
|
drop table t1;
|
|
--sync_slave_with_master
|
|
|
|
--echo # Case 3B: UNSAFE - all column specified.
|
|
--connection master
|
|
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT,
|
|
UNIQUE(b), c int, d int ) engine=innodb;
|
|
sync_slave_with_master;
|
|
connection master;
|
|
INSERT INTO t1 VALUES (1, 1, 1, 1);
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES (2, NULL, 2, 2) ON DUPLICATE KEY UPDATE c=VALUES(c);
|
|
--connection master1
|
|
INSERT INTO t1 VALUES(3, NULL, 2, 3) ON DUPLICATE KEY UPDATE c=VALUES(c);
|
|
--connection master
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
--sync_slave_with_master
|
|
--echo #same data as master
|
|
SELECT * FROM t1;
|
|
connection master;
|
|
drop table t1;
|
|
--sync_slave_with_master
|
|
|
|
|
|
--echo # Case 3C: SAFE - only one unique key (PK) specified.
|
|
--connection master
|
|
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT,
|
|
UNIQUE(b), c int, d int ) engine=innodb;
|
|
sync_slave_with_master;
|
|
connection master;
|
|
INSERT INTO t1 VALUES (1, 1, 1, 1);
|
|
BEGIN;
|
|
INSERT INTO t1 (`a`, `c`, `d`) VALUES (2, 2, 2) ON DUPLICATE KEY UPDATE c=99;
|
|
--connection master1
|
|
INSERT INTO t1 (`a`, `c`, `d`) VALUES(3, 2, 3) ON DUPLICATE KEY UPDATE c=100;
|
|
--connection master
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
--sync_slave_with_master
|
|
--echo #same data as master
|
|
SELECT * FROM t1;
|
|
connection master;
|
|
drop table t1;
|
|
--sync_slave_with_master
|
|
|
|
--echo # Case 4: UNSAFE
|
|
--connection master
|
|
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY auto_increment, b INT,
|
|
UNIQUE(b), c int) engine=innodb;
|
|
sync_slave_with_master;
|
|
connection master;
|
|
INSERT INTO t1 VALUES (1, 1, 1);
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES (2, 1, 2) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master1
|
|
INSERT INTO t1 VALUES(2, 2, 3) ON DUPLICATE KEY UPDATE b=VALUES(b), c=VALUES(c);
|
|
--connection master
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
--connection slave
|
|
# show the error message
|
|
--let $slave_sql_errno= 1062
|
|
--let $show_slave_sql_error= 1
|
|
--source include/wait_for_slave_sql_error.inc
|
|
--echo #Different value from server
|
|
SELECT * FROM t1;
|
|
|
|
# restart replication for the next testcase
|
|
stop slave;
|
|
--source include/wait_for_slave_to_stop.inc
|
|
reset slave;
|
|
connection master;
|
|
reset master;
|
|
drop table t1;
|
|
connection slave;
|
|
start slave;
|
|
--source include/wait_for_slave_to_start.inc
|
|
|
|
--source include/rpl_end.inc
|