mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
BUG#41980 SBL, INSERT .. SELECT .. LIMIT = ERROR, even when @@SQL_LOG_BIN is 0 !
When binlog_format is STATEMENT and the statement is unsafe before, the unsafe warning/error message was issued without checking whether the SQL_LOG_BIN was turned on or not. Fixed with adding a sql_log_bin_toplevel flag in THD to check whether SQL_LOG_BIN is ON in current session whatever the current is in sp or not. mysql-test/suite/binlog/r/binlog_unsafe.result: Test case result for unsafe warning/error message mysql-test/suite/binlog/t/binlog_unsafe.test: Test case for unsafe message warning/error sql/set_var.cc: Adding a function set_option_log_bin_bit() which specailly handles to the change of SQL_LOG_BIN bit in order to set sql_log_bin_toplevel according to SQL_LOG_BIN current value at the same time. sql/sql_class.cc: Initialize the flag sql_log_bin_toplevel in THD::init(), and add the condition to check whether unsafe ror message was issued. sql/sql_class.h: Add a sql_log_bin_toplevel flag in THD to indicate whether the toplevel SQL_LOG_BIN is
This commit is contained in:
@ -227,3 +227,86 @@ UPDATE t1 SET b = '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' WHERE a = 'a' LIMIT 1;
|
||||
Warnings:
|
||||
Warning 1592 Statement is not safe to log in statement format.
|
||||
DROP TABLE t1;
|
||||
DROP TABLE IF EXISTS t1, t2;
|
||||
CREATE TABLE t1(i INT PRIMARY KEY);
|
||||
CREATE TABLE t2(i INT PRIMARY KEY);
|
||||
CREATE TABLE t3(i INT, ch CHAR(50));
|
||||
"Should issue message Statement is not safe to log in statement format."
|
||||
INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
|
||||
Warnings:
|
||||
Warning 1592 Statement is not safe to log in statement format.
|
||||
CREATE FUNCTION func6()
|
||||
RETURNS INT
|
||||
BEGIN
|
||||
INSERT INTO t1 VALUES (10);
|
||||
INSERT INTO t1 VALUES (11);
|
||||
INSERT INTO t1 VALUES (12);
|
||||
RETURN 0;
|
||||
END|
|
||||
"Should issue message Statement is not safe to log in statement format only once"
|
||||
INSERT INTO t3 VALUES(func6(), UUID());
|
||||
Warnings:
|
||||
Warning 1592 Statement is not safe to log in statement format.
|
||||
"Check whether SET @@SQL_LOG_BIN = 0/1 doesn't work in substatements"
|
||||
CREATE FUNCTION fun_check_log_bin() RETURNS INT
|
||||
BEGIN
|
||||
SET @@SQL_LOG_BIN = 0;
|
||||
INSERT INTO t1 VALUES(@@global.sync_binlog);
|
||||
RETURN 100;
|
||||
END|
|
||||
"One unsafe warning should be issued in the following statement"
|
||||
SELECT fun_check_log_bin();
|
||||
fun_check_log_bin()
|
||||
100
|
||||
Warnings:
|
||||
Warning 1592 Statement is not safe to log in statement format.
|
||||
"SQL_LOG_BIN should be ON still"
|
||||
SHOW VARIABLES LIKE "SQL_LOG_BIN";
|
||||
Variable_name Value
|
||||
sql_log_bin ON
|
||||
set @save_log_bin = @@SESSION.SQL_LOG_BIN;
|
||||
set @@SESSION.SQL_LOG_BIN = 0;
|
||||
"Should NOT have any warning message issued in the following statements"
|
||||
INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
|
||||
DROP TABLE t1,t2;
|
||||
"Should NOT have any warning message issued in the following func7() and trig"
|
||||
CREATE TABLE t1 (a INT);
|
||||
CREATE TABLE t2 (a CHAR(40));
|
||||
CREATE TABLE trigger_table (a CHAR(7));
|
||||
CREATE FUNCTION func7()
|
||||
RETURNS INT
|
||||
BEGIN
|
||||
INSERT INTO t1 VALUES (@@global.sync_binlog);
|
||||
INSERT INTO t1 VALUES (@@session.insert_id);
|
||||
INSERT INTO t2 SELECT UUID();
|
||||
INSERT INTO t2 VALUES (@@session.sql_mode);
|
||||
INSERT INTO t2 VALUES (@@global.init_slave);
|
||||
RETURN 0;
|
||||
END|
|
||||
SHOW VARIABLES LIKE "SQL_LOG_BIN";
|
||||
Variable_name Value
|
||||
sql_log_bin OFF
|
||||
SELECT func7();
|
||||
func7()
|
||||
0
|
||||
---- Insert from trigger ----
|
||||
CREATE TRIGGER trig
|
||||
BEFORE INSERT ON trigger_table
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO t1 VALUES (@@global.sync_binlog);
|
||||
INSERT INTO t1 VALUES (@@session.insert_id);
|
||||
INSERT INTO t1 VALUES (@@global.auto_increment_increment);
|
||||
INSERT INTO t2 SELECT UUID();
|
||||
INSERT INTO t2 VALUES (@@session.sql_mode);
|
||||
INSERT INTO t2 VALUES (@@global.init_slave);
|
||||
INSERT INTO t2 VALUES (@@hostname);
|
||||
END|
|
||||
INSERT INTO trigger_table VALUES ('bye.');
|
||||
DROP FUNCTION fun_check_log_bin;
|
||||
DROP FUNCTION func6;
|
||||
DROP FUNCTION func7;
|
||||
DROP TRIGGER trig;
|
||||
DROP TABLE t1, t2, t3, trigger_table;
|
||||
set @@SESSION.SQL_LOG_BIN = @save_log_bin;
|
||||
"End of tests"
|
||||
|
Reference in New Issue
Block a user