From 7d8b967a86f077754ad74cee6aff0543984beba4 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 31 Jul 2009 10:00:35 -0300 Subject: [PATCH] Bug#46265: Can not disable warning about unsafe statements for binary logging If using statement based replication (SBR), repeatedly calling statements which are unsafe for SBR will cause a warning message to be written to the error for each statement. This might lead to filling up the error log and there is no way to disable this behavior. The solution is to only log these message (about statements unsafe for statement based replication) if the log_warnings option is set. For example: SET GLOBAL LOG_WARNINGS = 0; INSERT INTO t1 VALUES(UUID()); SET GLOBAL LOG_WARNINGS = 1; INSERT INTO t1 VALUES(UUID()); In this case the message will be printed only once: [Warning] Statement may not be safe to log in statement format. Statement: INSERT INTO t1 VALUES(UUID()) mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result: Add test case result for Bug#46265 mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt: Make log_error value available. mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test: Add test case for Bug#46265 sql/sql_class.cc: Print warning only if the log_warnings is enabled. --- .../binlog/r/binlog_stm_unsafe_warning.result | 20 +++++++++++ .../t/binlog_stm_unsafe_warning-master.opt | 2 +- .../binlog/t/binlog_stm_unsafe_warning.test | 35 +++++++++++++++++++ sql/sql_class.cc | 3 +- 4 files changed, 58 insertions(+), 2 deletions(-) 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),