diff --git a/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result b/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result index 439bff0cfe1..edbd878982b 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result +++ b/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result @@ -28,3 +28,23 @@ 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 Statement may not be safe to log in statement format. +SET GLOBAL LOG_WARNINGS = 1; +INSERT INTO t1 VALUES(UUID(), 'Bug#46265'); +Warnings: +Note 1592 Statement may not be safe to log in statement format. +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 diff --git a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt index 24c2027e399..91466bcdea3 100644 --- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt +++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt @@ -1 +1 @@ ---binlog-ignore-db=b42851 +--binlog-ignore-db=b42851 --log-error diff --git a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test index 0bf685ea921..a5472952f08 100644 --- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test +++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test @@ -56,6 +56,8 @@ SET SQL_LOG_BIN= 1; -- echo ### FILTERED database => assertion: warnings ARE NOT shown +let $old_db= `SELECT DATABASE()`; + CREATE DATABASE b42851; USE b42851; @@ -71,3 +73,36 @@ DROP TABLE t1; # clean up DROP DATABASE b42851; + +eval USE $old_db; + +--echo # +--echo # Bug#46265: Can not disable warning about unsafe statements for binary logging +--echo # + +SET @old_log_warnings = @@log_warnings; + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(10)); +SET GLOBAL LOG_WARNINGS = 0; +INSERT INTO t1 VALUES(UUID(), 'Bug#46265'); +SET GLOBAL LOG_WARNINGS = 1; +INSERT INTO t1 VALUES(UUID(), 'Bug#46265'); +DROP TABLE t1; + +SET GLOBAL log_warnings = @old_log_warnings; + +let LOG_ERROR= `SELECT @@GLOBAL.log_error`; + +--echo # Count the number of times the "Unsafe" message was printed +--echo # to the error log. + +perl; + $log_error= $ENV{'LOG_ERROR'}; + open(FILE, "$log_error") or die("Unable to open $log_error: $!\n"); + $count = () = grep(/Bug#46265/g,); + print "Occurrences: $count\n"; + close(FILE); +EOF diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 54684e4987e..9db86214a6b 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3714,7 +3714,8 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg, push_warning(this, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_BINLOG_UNSAFE_STATEMENT, ER(ER_BINLOG_UNSAFE_STATEMENT)); - if (!(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED)) + if (global_system_variables.log_warnings && + !(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED)) { sql_print_warning("%s Statement: %.*s", ER(ER_BINLOG_UNSAFE_STATEMENT),