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())
This commit is contained in:
Davi Arnaut 2009-07-31 10:00:35 -03:00
parent 8f7a48ff58
commit e1c43705b9
4 changed files with 58 additions and 2 deletions

View File

@ -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

View File

@ -1 +1 @@
--binlog-ignore-db=b42851
--binlog-ignore-db=b42851 --log-error

View File

@ -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,<FILE>);
print "Occurrences: $count\n";
close(FILE);
EOF

View File

@ -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),