mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 19:41:47 +01:00
88b3205653
After BUG#36649, warnings for sub-statements are cleared when a new sub-statement is started. This is problematic since it suppresses warnings for unsafe statements in some cases. It is important that we always give a warning to the client, because the user needs to know when there is a risk that the slave goes out of sync. We fixed the problem by generating warning messages for unsafe statements while returning from a stored procedure, function, trigger or while executing a top level statement. We also started checking unsafeness when both performance and log tables are used. This is necessary after the performance schema which does a distinction between performance and log tables. mysql-test/extra/rpl_tests/create_recursive_construct.inc: Changed the order of the calls in the procedure because the code that checks if a warning message is printed out expects that the first statement gives an warning what is not the case for INSERT INTO ta$CRC_ARG_level VALUES (47); mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result: Updated the result file. mysql-test/suite/binlog/r/binlog_unsafe.result: There are several changes here: (1) - Changed the CREATE PROCEDURE $CRC. (2) - The procedure $CRC was failing and the content of the binlog was being printed out, after fix (1) the failure disappeared. (3) - The warning message for unsafeness due to auto-increment collumns was changed. (4) - The warning message for unsafeness due to VERSION(), RAND() was changed. mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test: Tested filters. mysql-test/suite/binlog/t/binlog_unsafe.test: Reenabled the test case binlog_unsafe. mysql-test/suite/binlog/t/disabled.def: Reenabled the test case binlog_unsafe. mysql-test/suite/rpl/r/rpl_begin_commit_rollback.result: Updated the result file. mysql-test/suite/rpl/r/rpl_non_direct_stm_mixing_engines.result: Updated the result file. mysql-test/suite/rpl/r/rpl_stm_auto_increment_bug33029.result: Updated the result file. sql/sql_class.cc: Moved the stmt_accessed_table_flag variable and related information to the LEX as we need the variable reset after each statement even inside a stored procedure, what did not happen if the information was in the THD. Changed the routine in the THD::binlog_query that prints the warning messages to avoid trying to print them when inside a stored procedure, function or trigger. Checked for unsafeness when both performance and log tables where used. After the introduction of the performance schema, we need to check both.
96 lines
4.8 KiB
Text
96 lines
4.8 KiB
Text
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.");
|
|
### NOT filtered database => assertion: warnings ARE shown
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a int, b int, primary key (a));
|
|
INSERT INTO t1 VALUES (1,2), (2,3);
|
|
UPDATE t1 SET b='4' WHERE a=1 LIMIT 1;
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted.
|
|
UPDATE t1 SET b='5' WHERE a=2 ORDER BY a LIMIT 1;
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted.
|
|
DROP TABLE t1;
|
|
### NOT filtered database => assertion: binlog disabled and warnings ARE NOT shown
|
|
SET SQL_LOG_BIN= 0;
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a int, b int, primary key (a));
|
|
INSERT INTO t1 VALUES (1,2), (2,3);
|
|
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;
|
|
SET SQL_LOG_BIN= 1;
|
|
### FILTERED database => assertion: warnings ARE NOT shown
|
|
CREATE DATABASE b42851;
|
|
USE b42851;
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a int, b int, primary key (a));
|
|
INSERT INTO t1 VALUES (1,2), (2,3);
|
|
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;
|
|
CREATE TABLE t1 (a VARCHAR(1000));
|
|
INSERT INTO t1 VALUES (CURRENT_USER());
|
|
INSERT INTO t1 VALUES (FOUND_ROWS());
|
|
INSERT INTO t1 VALUES (GET_LOCK('tmp', 1));
|
|
INSERT INTO t1 VALUES (IS_FREE_LOCK('tmp'));
|
|
INSERT INTO t1 VALUES (IS_USED_LOCK('tmp'));
|
|
INSERT INTO t1 VALUES (LOAD_FILE('../../std_data/words2.dat'));
|
|
INSERT INTO t1 VALUES (MASTER_POS_WAIT('dummy arg', 4711, 1));
|
|
INSERT INTO t1 VALUES (RELEASE_LOCK('tmp'));
|
|
INSERT INTO t1 VALUES (ROW_COUNT());
|
|
INSERT INTO t1 VALUES (SESSION_USER());
|
|
INSERT INTO t1 VALUES (SLEEP(1));
|
|
INSERT INTO t1 VALUES (SYSDATE());
|
|
INSERT INTO t1 VALUES (SYSTEM_USER());
|
|
INSERT INTO t1 VALUES (USER());
|
|
INSERT INTO t1 VALUES (UUID());
|
|
INSERT INTO t1 VALUES (UUID_SHORT());
|
|
INSERT INTO t1 VALUES (VERSION());
|
|
INSERT INTO t1 VALUES (RAND());
|
|
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 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
|
|
SET GLOBAL LOG_WARNINGS = 1;
|
|
INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
|
|
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
|
|
DROP TABLE IF EXISTS t1, t2;
|
|
CREATE TABLE t1 (a int);
|
|
CREATE TABLE t2 (a int auto_increment primary key, b int);
|
|
CREATE TRIGGER tr_bug50192 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t2 (b) VALUES (1);
|
|
CREATE FUNCTION sf_bug50192() RETURNS INTEGER
|
|
BEGIN
|
|
INSERT INTO t2(b) VALUES(2);
|
|
RETURN 1;
|
|
END |
|
|
INSERT INTO t1 VALUES (0);
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
|
|
SHOW WARNINGS;
|
|
Level Code Message
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
|
|
SELECT sf_bug50192();
|
|
sf_bug50192()
|
|
1
|
|
Warnings:
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
|
|
SHOW WARNINGS;
|
|
Level Code Message
|
|
Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
|
|
DROP FUNCTION sf_bug50192;
|
|
DROP TRIGGER tr_bug50192;
|
|
DROP TABLE t1, t2;
|