#At file:///home/ngb/mysql/bzr/bugteam-5.1-bug41980/
2805 Guangbao Ni 2009-02-18
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 condition to check if SQL_LOG_BIN is turned on.
added:
mysql-test/suite/binlog/r/binlog_not_safe_warning.result
mysql-test/suite/binlog/t/binlog_not_safe_warning.test
modified:
sql/sql_class.cc
per-file messages:
mysql-test/suite/binlog/r/binlog_not_safe_warning.result
Test case result for unsafe warning/error message
mysql-test/suite/binlog/t/binlog_not_safe_warning.test
Test case for unsafe message warning/error
sql/sql_class.cc
Add a condition (sql_log_bin=1) for if statement
in order to prevent from issuing the warning/error message
when SQL_LOG_BIN is 0.
=== added file 'mysql-test/suite/binlog/r/binlog_not_safe_warning.result'
--- a/mysql-test/suite/binlog/r/binlog_not_safe_warning.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_not_safe_warning.result 2009-02-18 18:24:25 +0000
@@ -0,0 +1,14 @@
+drop table if exists t1, t2;
+create table t1(i int primary key);
+create table t2(i int primary key);
+"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.
+set @@SQL_LOG_BIN=0;
+"Should NOT have any warning message issued in the following statements"
+insert into t1 select * from t2 limit 1;
+set @@SQL_MODE=STRICT_ALL_TABLES;
+insert into t1 select * from t2 limit 1;
+drop table t1, t2;
+"End of tests"
=== added file 'mysql-test/suite/binlog/t/binlog_not_safe_warning.test'
--- a/mysql-test/suite/binlog/t/binlog_not_safe_warning.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_not_safe_warning.test 2009-02-18 18:24:25 +0000
@@ -0,0 +1,38 @@
+# ==== Purpose ====
+#
+# Purpose for testing if the warning/error message is/isn't issued
+# when SQL_LOG_BIN is turned on/off.
+#
+# ==== Method ====
+# 1. Execute a unsafe statement when SQL_LOG_BIN is turned ON,
+# a warning/error should be issued
+# 2. Execute a unsafe statement when @@SQL_LOG_BIN is turned OFF,
+# NO warning/error is issued
+#
+# ==== Related bugs ====
+#
+#For bug#41980, SBL, INSERT .. SELECT .. LIMIT = ERROR, even when @@SQL_LOG_BIN is 0
+#
+
+# Requires statement logging
+-- source include/have_binlog_format_statement.inc
+
+--disable_warnings
+drop table if exists t1, t2;
+--enable_warnings
+create table t1(i int primary key);
+create table t2(i int primary key);
+
+--echo "Should issue message Statement is not safe to log in statement format."
+insert into t1 select * from t2 limit 1;
+
+set @@SQL_LOG_BIN=0;
+--echo "Should NOT have any warning message issued in the following statements"
+insert into t1 select * from t2 limit 1;
+
+set @@SQL_MODE=STRICT_ALL_TABLES;
+insert into t1 select * from t2 limit 1;
+
+#clean up
+drop table t1, t2;
+--echo "End of tests"
=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc 2009-02-13 16:20:56 +0000
+++ b/sql/sql_class.cc 2009-02-18 18:24:25 +0000
@@ -3662,7 +3662,8 @@ int THD::binlog_query(THD::enum_binlog_q
If we are in statement mode and trying to log an unsafe statement,
we should print a warning.
*/
- if (lex->is_stmt_unsafe() &&
+ if ((options & OPTION_BIN_LOG) &&
+ lex->is_stmt_unsafe() &&
variables.binlog_format == BINLOG_FORMAT_STMT)
{
push_warning(this, MYSQL_ERROR::WARN_LEVEL_WARN,