mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 19:41:47 +01:00
66481aebb0
Post-push fix. Problem: After the original bugfix, if a statement is unsafe, binlog_format=mixed, and engine is statement-only, a warning was generated and the statement executed. However, it is a fundamental principle of binlogging that binlog_format=mixed should guarantee correct logging, no compromise. So correct behavior is to generate an error and don't execute the statement. Fix: Generate error instead of warning. Since issue_unsafe_warnings can only generate one error message, this allows us to simplify the code a bit too: decide_logging_format does not have to save the error code for issue_unsafe_warnings mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: updated result file mysql-test/suite/binlog/r/binlog_stm_ps.result: updated result file mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result: updated result file mysql-test/suite/binlog/r/binlog_unsafe.result: updated result file mysql-test/suite/rpl/r/rpl_stm_found_rows.result: updated result file mysql-test/suite/rpl/r/rpl_stm_loadfile.result: updated result file mysql-test/suite/rpl_ndb/r/rpl_ndb_binlog_format_errors.result: updated result file mysql-test/suite/rpl_ndb/t/rpl_ndb_binlog_format_errors.test: updated test: - ER_BINLOG_UNSAFE_AND_STMT_ENGINE is now an error. - added test for multiple types of unsafety sql/share/errmsg.txt: - Reformulated ER_BINLOG_UNSAFE_AND_STMT_ENGINE to reflect that it is now an error, not a warning. - Added "Reason for unsafeness" to ER_BINLOG_UNSAFE_STATEMENT and ER_BINLOG_UNSAFE_AND_STMT_ENGINE. sql/sql_class.cc: In decide_logging_format: - generate an error immediately in case 3, instead of scheduling a warning to be generated later. also updated comments accordingly - in case 7, there is only one unsafe warning error code now, so we don't need to store it in binlog_unsafe_warning_flags (see changes in sql_lex.h) - fixed compilation warning in DBUG_PRINT In issue_binlog_warning: - moved array of error codes to sql_lex.h (so that they are accessible also from decide_logging_format) - simplified code after the first set of bits in binlog_unsafe_warning_flags was removed sql/sql_class.h: - got rid of enum_binlog_stmt_warning. It's not needed anymore since we only have one type of unsafe warning (one of them turned into an error) - updated comments accordingly sql/sql_lex.cc: added initialization of the array of error codes that has been moved from THD::issue_unsafe_warnings to LEX. sql/sql_lex.h: Moved array of error codes from THD::issue_unsafe_warnings to LEX.
110 lines
3.1 KiB
Text
110 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;
|
|
==== Simple test ====
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
a
|
|
7
|
|
SELECT FOUND_ROWS() INTO @a;
|
|
INSERT INTO logtbl VALUES(1,1,@a);
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a < 5 ORDER BY a LIMIT 1;
|
|
a
|
|
1
|
|
SELECT FOUND_ROWS() INTO @a;
|
|
INSERT INTO logtbl VALUES(1,2,@a);
|
|
SELECT * FROM logtbl WHERE sect = 1 ORDER BY sect,test;
|
|
sect test count
|
|
1 1 183
|
|
1 2 3
|
|
**** On Slave ****
|
|
SELECT * FROM logtbl WHERE sect = 1 ORDER BY sect,test;
|
|
sect test count
|
|
1 1 183
|
|
1 2 3
|
|
==== Stored procedure ====
|
|
**** On Master ****
|
|
CREATE PROCEDURE calc_and_log(sect INT, test INT) BEGIN
|
|
DECLARE cnt INT;
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a < 5 ORDER BY a LIMIT 1;
|
|
SELECT FOUND_ROWS() INTO cnt;
|
|
INSERT INTO logtbl VALUES(sect,test,cnt);
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
SELECT FOUND_ROWS() INTO cnt;
|
|
INSERT INTO logtbl VALUES(sect,test+1,cnt);
|
|
END $$
|
|
CALL calc_and_log(2,1);
|
|
a
|
|
1
|
|
a
|
|
7
|
|
Warnings:
|
|
Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted.
|
|
Note 1592 Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a system function whose value may differ on slave.
|
|
CREATE PROCEDURE just_log(sect INT, test INT, found_rows INT) BEGIN
|
|
INSERT INTO logtbl VALUES (sect,test,found_rows);
|
|
END $$
|
|
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a > 5 ORDER BY a LIMIT 1;
|
|
a
|
|
7
|
|
SELECT FOUND_ROWS() INTO @found_rows;
|
|
CALL just_log(2,3,@found_rows);
|
|
SELECT * FROM logtbl WHERE sect = 2 ORDER BY sect,test;
|
|
sect test count
|
|
2 1 3
|
|
2 2 183
|
|
2 3 183
|
|
**** On Slave ****
|
|
SELECT * FROM logtbl WHERE sect = 2 ORDER BY sect,test;
|
|
sect test count
|
|
2 1 3
|
|
2 2 183
|
|
2 3 183
|
|
==== Stored functions ====
|
|
**** On Master ****
|
|
CREATE FUNCTION log_rows(sect INT, test INT, found_rows INT)
|
|
RETURNS INT
|
|
BEGIN
|
|
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
|
|
7
|
|
SELECT FOUND_ROWS() INTO @found_rows;
|
|
SELECT log_rows(3,1,@found_rows), log_rows(3,2,@found_rows);
|
|
log_rows(3,1,@found_rows) log_rows(3,2,@found_rows)
|
|
183 183
|
|
SELECT * FROM logtbl WHERE sect = 3 ORDER BY sect,test;
|
|
sect test count
|
|
3 1 183
|
|
3 2 183
|
|
**** On Slave ****
|
|
SELECT * FROM logtbl WHERE sect = 3 ORDER BY sect,test;
|
|
sect test count
|
|
3 1 183
|
|
3 2 183
|
|
==== Cleanup ====
|
|
**** On Master ****
|
|
DROP TABLE t1, logtbl;
|
|
DROP PROCEDURE just_log;
|
|
DROP PROCEDURE calc_and_log;
|
|
DROP FUNCTION log_rows;
|
|
**** Resetting master and slave ****
|
|
include/stop_slave.inc
|
|
RESET SLAVE;
|
|
RESET MASTER;
|
|
include/start_slave.inc
|