mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 11:31:51 +01:00
8357596035
The thd->variables.option_bits & OPTION_BIN_LOG is currently abused: it's both a system variable and an implementation switch. The current approach to this option bit breaks the session variable encapsulation. Besides it is allowed to change @@session.sql_bin_log within a transaction what may lead to not correctly logging a transaction. To fix the problems, we created a thd->variables variable to represent the "sql_log_bin" and prohibited its update inside a transaction or sub-statement. mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result: Updated result file. The reason the warnings are removed is related to BUG#50312. mysql-test/suite/binlog/r/binlog_switch_inside_trans.result: Checks when is possible to change the option @@session.sql_log_bin. mysql-test/suite/binlog/t/binlog_switch_inside_trans.test: Checks when is possible to change the option @@session.sql_log_bin. mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result: Updated the result file with warnings that were being printed due to the wrong use of the thd->variables.option_bits and sql_log_bin_top_level variables. mysql-test/suite/rpl/r/rpl_stm_mixing_engines.result: Updated the result file with warnings that were being printed due to the wrong use of the thd->variables.option_bits and sql_log_bin_top_level variables. sql/share/errmsg-utf8.txt: Introduces two error messages to notify that the @@session.sql_log_bin cannot be changed inside a sub-statement or transaction. sql/sql_base.cc: Removes the variable sql_log_bin_toplevel and uses the session variable sql_log_bin. sql/sql_class.cc: Replaces the variable sql_log_bin_toplevel by the (variables.option_bits & OPTION_BIN_LOG). sql/sql_class.h: Removes the variable sql_log_bin_toplevel and creates a session variable sql_log_bin. sql/sys_vars.cc: Checks when the sql_log_bin can be correctly updated.
74 lines
3.5 KiB
Text
74 lines
3.5 KiB
Text
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.");
|
|
### NOT filtered database => assertion: warnings ARE shown
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a int, b int, primary key (a));
|
|
INSERT INTO t1 VALUES (1,2), (2,3);
|
|
UPDATE t1 SET b='4' WHERE a=1 LIMIT 1;
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted.
|
|
UPDATE t1 SET b='5' WHERE a=2 ORDER BY a LIMIT 1;
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted.
|
|
DROP TABLE t1;
|
|
### NOT filtered database => assertion: binlog disabled and warnings ARE NOT shown
|
|
SET SQL_LOG_BIN= 0;
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a int, b int, primary key (a));
|
|
INSERT INTO t1 VALUES (1,2), (2,3);
|
|
UPDATE t1 SET b='4' WHERE a=1 LIMIT 1;
|
|
UPDATE t1 SET b='5' WHERE a=2 ORDER BY a LIMIT 1;
|
|
DROP TABLE t1;
|
|
SET SQL_LOG_BIN= 1;
|
|
### FILTERED database => assertion: warnings ARE NOT shown
|
|
CREATE DATABASE b42851;
|
|
USE b42851;
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a int, b int, primary key (a));
|
|
INSERT INTO t1 VALUES (1,2), (2,3);
|
|
UPDATE t1 SET b='4' WHERE a=1 LIMIT 1;
|
|
UPDATE t1 SET b='5' WHERE a=2 ORDER BY a LIMIT 1;
|
|
DROP TABLE t1;
|
|
DROP DATABASE b42851;
|
|
USE test;
|
|
#
|
|
# Bug#46265: Can not disable warning about unsafe statements for binary logging
|
|
#
|
|
SET @old_log_warnings = @@log_warnings;
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(10));
|
|
SET GLOBAL LOG_WARNINGS = 0;
|
|
INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
|
|
SET GLOBAL LOG_WARNINGS = 1;
|
|
INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
|
|
DROP TABLE t1;
|
|
SET GLOBAL log_warnings = @old_log_warnings;
|
|
# Count the number of times the "Unsafe" message was printed
|
|
# to the error log.
|
|
Occurrences: 1
|
|
DROP TABLE IF EXISTS t1, t2;
|
|
CREATE TABLE t1 (a int);
|
|
CREATE TABLE t2 (a int auto_increment primary key, b int);
|
|
CREATE TRIGGER tr_bug50192 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 (b) VALUES (1);
|
|
CREATE FUNCTION sf_bug50192() RETURNS INTEGER
|
|
BEGIN
|
|
INSERT INTO t2(b) VALUES(2);
|
|
RETURN 1;
|
|
END |
|
|
INSERT INTO t1 VALUES (0);
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
|
|
SHOW WARNINGS;
|
|
Level Code Message
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
|
|
SELECT sf_bug50192();
|
|
sf_bug50192()
|
|
1
|
|
SHOW WARNINGS;
|
|
Level Code Message
|
|
DROP FUNCTION sf_bug50192;
|
|
DROP TRIGGER tr_bug50192;
|
|
DROP TABLE t1, t2;
|