mirror of
https://github.com/MariaDB/server.git
synced 2025-01-21 14:32:34 +01:00
f3985c649d
General overview: The logic for switching to row format when binlog_format=MIXED had numerous flaws. The underlying problem was the lack of a consistent architecture. General purpose of this changeset: This changeset introduces an architecture for switching to row format when binlog_format=MIXED. It enforces the architecture where it has to. It leaves some bugs to be fixed later. It adds extensive tests to verify that unsafe statements work as expected and that appropriate errors are produced by problems with the selection of binlog format. It was not practical to split this into smaller pieces of work. Problem 1: To determine the logging mode, the code has to take several parameters into account (namely: (1) the value of binlog_format; (2) the capabilities of the engines; (3) the type of the current statement: normal, unsafe, or row injection). These parameters may conflict in several ways, namely: - binlog_format=STATEMENT for a row injection - binlog_format=STATEMENT for an unsafe statement - binlog_format=STATEMENT for an engine only supporting row logging - binlog_format=ROW for an engine only supporting statement logging - statement is unsafe and engine does not support row logging - row injection in a table that does not support statement logging - statement modifies one table that does not support row logging and one that does not support statement logging Several of these conflicts were not detected, or were detected with an inappropriate error message. The problem of BUG#39934 was that no appropriate error message was written for the case when an engine only supporting row logging executed a row injection with binlog_format=ROW. However, all above cases must be handled. Fix 1: Introduce new error codes (sql/share/errmsg.txt). Ensure that all conditions are detected and handled in decide_logging_format() Problem 2: The binlog format shall be determined once per statement, in decide_logging_format(). It shall not be changed before or after that. Before decide_logging_format() is called, all information necessary to determine the logging format must be available. This principle ensures that all unsafe statements are handled in a consistent way. However, this principle is not followed: thd->set_current_stmt_binlog_row_based_if_mixed() is called in several places, including from code executing UPDATE..LIMIT, INSERT..SELECT..LIMIT, DELETE..LIMIT, INSERT DELAYED, and SET @@binlog_format. After Problem 1 was fixed, that caused inconsistencies where these unsafe statements would not print the appropriate warnings or errors for some of the conflicts. Fix 2: Remove calls to THD::set_current_stmt_binlog_row_based_if_mixed() from code executed after decide_logging_format(). Compensate by calling the set_current_stmt_unsafe() at parse time. This way, all unsafe statements are detected by decide_logging_format(). Problem 3: INSERT DELAYED is not unsafe: it is logged in statement format even if binlog_format=MIXED, and no warning is printed even if binlog_format=STATEMENT. This is BUG#45825. Fix 3: Made INSERT DELAYED set itself to unsafe at parse time. This allows decide_logging_format() to detect that a warning should be printed or the binlog_format changed. Problem 4: LIMIT clause were not marked as unsafe when executed inside stored functions/triggers/views/prepared statements. This is BUG#45785. Fix 4: Make statements containing the LIMIT clause marked as unsafe at parse time, instead of at execution time. This allows propagating unsafe-ness to the view.
138 lines
3.1 KiB
Text
138 lines
3.1 KiB
Text
stop slave;
|
|
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
|
|
reset master;
|
|
reset slave;
|
|
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
|
|
start slave;
|
|
==== Initialize ====
|
|
**** On Master ****
|
|
CREATE TABLE t1 (a INT);
|
|
CREATE TABLE logtbl (sect INT, test INT, count INT);
|
|
INSERT INTO t1 VALUES (1),(2),(3);
|
|
INSERT INTO t1 SELECT 2*a+3 FROM t1;
|
|
INSERT INTO t1 SELECT 2*a+3 FROM t1;
|
|
INSERT INTO t1 SELECT 2*a+3 FROM t1;
|
|
INSERT INTO t1 SELECT 2*a+3 FROM t1;
|
|
INSERT INTO t1 SELECT 2*a+3 FROM t1;
|
|
INSERT INTO t1 SELECT 2*a+3 FROM t1;
|
|
==== Checking a procedure ====
|
|
**** On Master ****
|
|
CREATE PROCEDURE just_log(sect INT, test INT) BEGIN
|
|
INSERT INTO logtbl VALUES (sect,test,FOUND_ROWS());
|
|
END $$
|
|
**** On Master 1 ****
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
a
|
|
7
|
|
CALL just_log(1,1);
|
|
**** On Master ****
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
a
|
|
7
|
|
CALL just_log(1,2);
|
|
**** On Master 1 ****
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a < 5 ORDER BY a LIMIT 1;
|
|
a
|
|
1
|
|
CALL just_log(1,3);
|
|
**** On Master ****
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
a
|
|
7
|
|
CALL just_log(1,4);
|
|
SELECT * FROM logtbl WHERE sect = 1 ORDER BY sect,test;
|
|
sect test count
|
|
1 1 183
|
|
1 2 183
|
|
1 3 3
|
|
1 4 183
|
|
**** On Slave ****
|
|
SELECT * FROM logtbl WHERE sect = 1 ORDER BY sect,test;
|
|
sect test count
|
|
1 1 183
|
|
1 2 183
|
|
1 3 3
|
|
1 4 183
|
|
==== Checking a stored function ====
|
|
**** On Master ****
|
|
CREATE FUNCTION log_rows(sect INT, test INT)
|
|
RETURNS INT
|
|
BEGIN
|
|
DECLARE found_rows INT;
|
|
SELECT FOUND_ROWS() INTO found_rows;
|
|
INSERT INTO logtbl VALUES(sect,test,found_rows);
|
|
RETURN found_rows;
|
|
END $$
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a < 5 ORDER BY a LIMIT 1;
|
|
a
|
|
1
|
|
SELECT log_rows(2,1), log_rows(2,2);
|
|
log_rows(2,1) log_rows(2,2)
|
|
3 3
|
|
CREATE TABLE t2 (a INT, b INT);
|
|
CREATE TRIGGER t2_tr BEFORE INSERT ON t2 FOR EACH ROW
|
|
BEGIN
|
|
INSERT INTO logtbl VALUES (NEW.a, NEW.b, FOUND_ROWS());
|
|
END $$
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a < 5 ORDER BY a LIMIT 1;
|
|
a
|
|
1
|
|
INSERT INTO t2 VALUES (2,3), (2,4);
|
|
DROP TRIGGER t2_tr;
|
|
CREATE TRIGGER t2_tr BEFORE INSERT ON t2 FOR EACH ROW
|
|
BEGIN
|
|
DECLARE dummy INT;
|
|
SELECT log_rows(NEW.a, NEW.b) INTO dummy;
|
|
END $$
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
a
|
|
7
|
|
INSERT INTO t2 VALUES (2,5), (2,6);
|
|
DROP TRIGGER t2_tr;
|
|
CREATE PROCEDURE log_me_inner(sect INT, test INT)
|
|
BEGIN
|
|
DECLARE dummy INT;
|
|
SELECT log_rows(sect, test) INTO dummy;
|
|
SELECT log_rows(sect, test+1) INTO dummy;
|
|
END $$
|
|
CREATE PROCEDURE log_me(sect INT, test INT)
|
|
BEGIN
|
|
CALL log_me_inner(sect,test);
|
|
END $$
|
|
CREATE TRIGGER t2_tr BEFORE INSERT ON t2 FOR EACH ROW
|
|
BEGIN
|
|
CALL log_me(NEW.a, NEW.b);
|
|
END $$
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
a
|
|
7
|
|
INSERT INTO t2 VALUES (2,5), (2,6);
|
|
SELECT * FROM logtbl WHERE sect = 2 ORDER BY sect,test;
|
|
sect test count
|
|
2 1 3
|
|
2 2 3
|
|
2 3 3
|
|
2 4 3
|
|
2 5 183
|
|
2 5 183
|
|
2 6 183
|
|
2 6 0
|
|
2 6 183
|
|
2 7 0
|
|
SELECT * FROM logtbl WHERE sect = 2 ORDER BY sect,test;
|
|
sect test count
|
|
2 1 3
|
|
2 2 3
|
|
2 3 3
|
|
2 4 3
|
|
2 5 183
|
|
2 5 183
|
|
2 6 183
|
|
2 6 0
|
|
2 6 183
|
|
2 7 0
|
|
DROP TABLE t1, t2, logtbl;
|
|
DROP PROCEDURE just_log;
|
|
DROP PROCEDURE log_me;
|
|
DROP PROCEDURE log_me_inner;
|
|
DROP FUNCTION log_rows;
|