summaryrefslogtreecommitdiff
path: root/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test
blob: 874bb015a075d0371b0f12e4b31fff5a95b6802a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# BUG#42851: Spurious "Statement is not safe to log in statement
#            format." warnings
#
# WHY
# ===
#   
#   This test aims at checking that the fix that removes spurious
#   entries in the error log when the statement is filtered out from
#   binlog, is working.
#
# HOW
# ===
#
#   The test case is split into three assertions when issuing statements
#   containing LIMIT and ORDER BY:
#
#     i) issue statements in database that is not filtered => check
#        that warnings ARE shown;
#
#    ii) issue statements in database that is not filtered, but with
#        binlog disabled => check that warnings ARE NOT shown;
#
#   iii) issue statements in database that is filtered => check that
#        warnings ARE NOT shown.

-- source include/have_log_bin.inc
-- source include/have_binlog_format_statement.inc
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted. .*");
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a system function whose value may differ on slave. .*");
call mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement invokes a trigger or a stored function that inserts into AUTO_INCREMENT column");

-- echo ### NOT filtered database => assertion: warnings ARE shown

-- disable_warnings
DROP TABLE IF EXISTS t1;
-- enable_warnings

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;

-- echo ### NOT filtered database => assertion: binlog disabled and warnings ARE NOT shown

SET SQL_LOG_BIN= 0;

-- disable_warnings
DROP TABLE IF EXISTS t1;
-- enable_warnings

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;

-- echo ### FILTERED database => assertion: warnings ARE NOT shown

let $old_db= `SELECT DATABASE()`;

CREATE DATABASE b42851;
USE b42851;

-- disable_warnings
DROP TABLE IF EXISTS t1;
-- enable_warnings

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;

# 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`;
if(!`select LENGTH('$log_error_')`)
{
  # MySQL Server on windows is started with --console and thus
  # does not know the location of its .err log, use default location
  let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err;
}
# Assign env variable LOG_ERROR
let LOG_ERROR=$log_error_;

--echo # Count the number of times the "Unsafe" message was printed
--echo # to the error log.

perl;
  use strict;
  my $log_error= $ENV{'LOG_ERROR'} or die "LOG_ERROR not set";
  open(FILE, "$log_error") or die("Unable to open $log_error: $!\n");
  my $count = () = grep(/Bug#46265/g,<FILE>);
  print "Occurrences: $count\n";
  close(FILE);
EOF

# bug#50192: diplaying the unsafe warning comes out to the user warning stack

-- disable_warnings
DROP TABLE IF EXISTS t1, t2;
-- enable_warnings

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);

DELIMITER |;

CREATE FUNCTION sf_bug50192() RETURNS INTEGER
BEGIN
   INSERT INTO t2(b) VALUES(2);
   RETURN 1;
END |

DELIMITER ;|

INSERT INTO t1 VALUES (0);
SHOW WARNINGS;
SELECT sf_bug50192();
SHOW WARNINGS;

# cleanup

DROP FUNCTION sf_bug50192;
DROP TRIGGER tr_bug50192;
DROP TABLE t1, t2;