# At a local mysql-5.1-bugteam repository of davi
3052 Davi Arnaut 2009-07-31
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.
modified:
mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result
mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt
mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test
sql/sql_class.cc
=== modified file 'mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result 2009-06-27 13:18:47 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result 2009-07-31 04:17:46 +0000
@@ -28,3 +28,22 @@ 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 the "Unsafe" message was logged to the error log.
+Occurrences: 1
=== modified file 'mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt'
--- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt 2009-06-27 13:18:47 +0000
+++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt 2009-07-31 04:17:46 +0000
@@ -1 +1 @@
---binlog-ignore-db=b42851
+--binlog-ignore-db=b42851 --log-error
=== modified file 'mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test'
--- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test 2009-06-27 13:18:47 +0000
+++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test 2009-07-31 04:17:46 +0000
@@ -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,35 @@ 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 the "Unsafe" message was logged 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,<FILE>);
+ print "Occurrences: $count\n";
+ close(FILE);
+EOF
=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc 2009-07-24 16:04:55 +0000
+++ b/sql/sql_class.cc 2009-07-31 04:17:46 +0000
@@ -3714,7 +3714,8 @@ int THD::binlog_query(THD::enum_binlog_q
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 > 0) &&
+ !(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED))
{
sql_print_warning("%s Statement: %.*s",
ER(ER_BINLOG_UNSAFE_STATEMENT),
Attachment: [text/bzr-bundle] bzr/davi.arnaut@sun.com-20090731041746-284q3bpp4tejvfat.bundle