~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to mysql-test/suite/binlog/t/binlog_unsafe.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ==== Purpose ====
 
2
#
 
3
# Some statements can not be written to the binlog in a safe manner
 
4
# with statement-based replication, either because they rely on
 
5
# features that are local to the server they are replicated from
 
6
# (e.g., @@variables), or because they include nondeterministic
 
7
# queries (e.g., LIMIT), or because the time at which the query is
 
8
# executed cannot be determined (e.g., INSERT DELAYED).  Such
 
9
# statements should be marked unsafe.  All unsafe statements should
 
10
# give a warning.
 
11
#
 
12
# This test verifies that a warning is generated for statements that
 
13
# should be unsafe, when they are executed under statement mode
 
14
# logging.
 
15
#
 
16
# All variables should be unsafe, with some exceptions.  Therefore,
 
17
# this test also verifies that the exceptions do *not* generare a
 
18
# warning.
 
19
#
 
20
#
 
21
# ==== Method ====
 
22
#
 
23
# We try an INSERT DELAYED statement and verify that a warning is
 
24
# issued.
 
25
#
 
26
# We try to insert unsafe variables into a table in several ways:
 
27
# directly with an INSERT statement, from a stored procedure, from a
 
28
# stored function, from a trigger, from a prepared statement, and from
 
29
# a complicated nesting of triggers, functions, procedures, and
 
30
# prepared statements.  In all cases, a warning should be issued.
 
31
#
 
32
# We try to insert the variables that should not be unsafe into a
 
33
# table, and verify that *no* warning is issued.
 
34
#
 
35
#
 
36
# ==== Related bugs and worklogs ====
 
37
#
 
38
# WL#3339: Issue warnings when statement-based replication may fail
 
39
# BUG#31168: @@hostname does not replicate
 
40
# BUG#34732: mysqlbinlog does not print default values for auto_increment variables
 
41
# BUG#34768: nondeterministic INSERT using LIMIT logged in stmt mode if binlog_format=mixed
 
42
#
 
43
#
 
44
# ==== Related test cases ====
 
45
#
 
46
# rpl.rpl_variables verifies that variables which cannot be replicated
 
47
# safely in statement mode are replicated correctly in mixed or row
 
48
# mode.
 
49
#
 
50
# rpl.rpl_variables_stm tests the small subset of variables that
 
51
# actually can be replicated safely in statement mode.
 
52
#
 
53
#
 
54
# ==== Todo ====
 
55
#
 
56
# There are several other ways to create unsafe statements: see, e.g.,
 
57
# WL#3339, BUG#34768.
 
58
 
 
59
source include/have_log_bin.inc;
 
60
source include/have_binlog_format_statement.inc;
 
61
 
 
62
--echo ==== Setup tables ====
 
63
 
 
64
CREATE TABLE t1 (a INT);
 
65
CREATE TABLE t2 (a CHAR(40));
 
66
CREATE TABLE t3 (a INT AUTO_INCREMENT PRIMARY KEY);
 
67
CREATE TABLE trigger_table (a CHAR(7));
 
68
CREATE TABLE trigger_table2 (a INT);
 
69
 
 
70
 
 
71
--echo ==== Non-deterministic statements ====
 
72
 
 
73
INSERT DELAYED INTO t1 VALUES (5);
 
74
 
 
75
 
 
76
--echo ==== Some variables that *should* be unsafe ====
 
77
 
 
78
--echo ---- Insert directly ----
 
79
 
 
80
INSERT INTO t1 VALUES (@@global.sync_binlog);
 
81
INSERT INTO t1 VALUES (@@session.insert_id);
 
82
INSERT INTO t1 VALUES (@@global.auto_increment_increment);
 
83
INSERT INTO t2 SELECT UUID();
 
84
INSERT INTO t2 VALUES (@@session.sql_mode);
 
85
INSERT INTO t2 VALUES (@@global.init_slave);
 
86
INSERT INTO t2 VALUES (@@hostname);
 
87
 
 
88
--echo ---- Insert from stored procedure ----
 
89
 
 
90
DELIMITER |;
 
91
CREATE PROCEDURE proc()
 
92
BEGIN
 
93
  INSERT INTO t1 VALUES (@@global.sync_binlog);
 
94
  INSERT INTO t1 VALUES (@@session.insert_id);
 
95
  INSERT INTO t1 VALUES (@@global.auto_increment_increment);
 
96
  INSERT INTO t2 SELECT UUID();
 
97
  INSERT INTO t2 VALUES (@@session.sql_mode);
 
98
  INSERT INTO t2 VALUES (@@global.init_slave);
 
99
  INSERT INTO t2 VALUES (@@hostname);
 
100
END|
 
101
DELIMITER ;|
 
102
 
 
103
CALL proc();
 
104
 
 
105
--echo ---- Insert from stored function ----
 
106
 
 
107
DELIMITER |;
 
108
CREATE FUNCTION func()
 
109
RETURNS INT
 
110
BEGIN
 
111
  INSERT INTO t1 VALUES (@@global.sync_binlog);
 
112
  INSERT INTO t1 VALUES (@@session.insert_id);
 
113
  INSERT INTO t1 VALUES (@@global.auto_increment_increment);
 
114
  INSERT INTO t2 SELECT UUID();
 
115
  INSERT INTO t2 VALUES (@@session.sql_mode);
 
116
  INSERT INTO t2 VALUES (@@global.init_slave);
 
117
  INSERT INTO t2 VALUES (@@hostname);
 
118
  RETURN 0;
 
119
END|
 
120
DELIMITER ;|
 
121
 
 
122
SELECT func();
 
123
 
 
124
--echo ---- Insert from trigger ----
 
125
 
 
126
DELIMITER |;
 
127
CREATE TRIGGER trig
 
128
BEFORE INSERT ON trigger_table
 
129
FOR EACH ROW
 
130
BEGIN
 
131
  INSERT INTO t1 VALUES (@@global.sync_binlog);
 
132
  INSERT INTO t1 VALUES (@@session.insert_id);
 
133
  INSERT INTO t1 VALUES (@@global.auto_increment_increment);
 
134
  INSERT INTO t2 SELECT UUID();
 
135
  INSERT INTO t2 VALUES (@@session.sql_mode);
 
136
  INSERT INTO t2 VALUES (@@global.init_slave);
 
137
  INSERT INTO t2 VALUES (@@hostname);
 
138
END|
 
139
DELIMITER ;|
 
140
 
 
141
INSERT INTO trigger_table VALUES ('bye.');
 
142
 
 
143
--echo ---- Insert from prepared statement ----
 
144
 
 
145
PREPARE p1 FROM 'INSERT INTO t1 VALUES (@@global.sync_binlog)';
 
146
PREPARE p2 FROM 'INSERT INTO t1 VALUES (@@session.insert_id)';
 
147
PREPARE p3 FROM 'INSERT INTO t1 VALUES (@@global.auto_increment_increment)';
 
148
PREPARE p4 FROM 'INSERT INTO t2 SELECT UUID()';
 
149
PREPARE p5 FROM 'INSERT INTO t2 VALUES (@@session.sql_mode)';
 
150
PREPARE p6 FROM 'INSERT INTO t2 VALUES (@@global.init_slave)';
 
151
PREPARE p7 FROM 'INSERT INTO t2 VALUES (@@hostname)';
 
152
 
 
153
EXECUTE p1; EXECUTE p2; EXECUTE p3; EXECUTE p4; EXECUTE p5;
 
154
EXECUTE p6; EXECUTE p7;
 
155
 
 
156
--echo ---- Insert from nested call of triggers / functions / procedures ----
 
157
 
 
158
DELIMITER |;
 
159
 
 
160
# proc1: cause trigger 'trig' above to be triggered.
 
161
CREATE PROCEDURE proc1()
 
162
  INSERT INTO trigger_table VALUES ('ha!')|
 
163
 
 
164
# func2: call proc1 above.
 
165
CREATE FUNCTION func2()
 
166
RETURNS INT
 
167
BEGIN
 
168
  CALL proc1();
 
169
  RETURN 0;
 
170
END|
 
171
 
 
172
# trig3: call func2 above
 
173
CREATE TRIGGER trig3
 
174
BEFORE INSERT ON trigger_table2
 
175
FOR EACH ROW
 
176
BEGIN
 
177
  DECLARE tmp INT;
 
178
  SELECT func2() INTO tmp;
 
179
END|
 
180
 
 
181
# proc4: cause trig3 above to be triggered.
 
182
CREATE PROCEDURE proc4()
 
183
  INSERT INTO trigger_table2 VALUES (1)|
 
184
 
 
185
# func5: call proc4 above.
 
186
CREATE FUNCTION func5()
 
187
RETURNS INT
 
188
BEGIN
 
189
  CALL proc4;
 
190
  RETURN 0;
 
191
END|
 
192
 
 
193
# prep6: call func5() above.
 
194
PREPARE prep6 FROM 'SELECT func5()'|
 
195
 
 
196
DELIMITER ;|
 
197
 
 
198
# try a complicated call path to trigger 'trig'.
 
199
EXECUTE prep6;
 
200
 
 
201
 
 
202
--echo ==== Variables that should *not* be unsafe ====
 
203
 
 
204
INSERT INTO t1 VALUES (@@session.pseudo_thread_id);
 
205
INSERT INTO t1 VALUES (@@session.pseudo_thread_id);
 
206
INSERT INTO t1 VALUES (@@session.foreign_key_checks);
 
207
INSERT INTO t1 VALUES (@@session.sql_auto_is_null);
 
208
INSERT INTO t1 VALUES (@@session.unique_checks);
 
209
INSERT INTO t1 VALUES (@@session.auto_increment_increment);
 
210
INSERT INTO t1 VALUES (@@session.auto_increment_offset);
 
211
INSERT INTO t2 VALUES (@@session.character_set_client);
 
212
INSERT INTO t2 VALUES (@@session.collation_connection);
 
213
INSERT INTO t2 VALUES (@@session.collation_server);
 
214
INSERT INTO t2 VALUES (@@session.time_zone);
 
215
INSERT INTO t2 VALUES (@@session.lc_time_names);
 
216
INSERT INTO t2 VALUES (@@session.collation_database);
 
217
INSERT INTO t2 VALUES (@@session.timestamp);
 
218
INSERT INTO t2 VALUES (@@session.last_insert_id);
 
219
SET @my_var= 4711;
 
220
INSERT INTO t1 VALUES (@my_var);
 
221
 
 
222
# using insert_id implicitly should be ok.
 
223
SET insert_id=12;
 
224
INSERT INTO t3 VALUES (NULL);
 
225
 
 
226
 
 
227
--echo ==== Clean up ====
 
228
 
 
229
DROP PROCEDURE proc;
 
230
DROP FUNCTION  func;
 
231
DROP TRIGGER   trig;
 
232
DROP PROCEDURE proc1;
 
233
DROP FUNCTION  func2;
 
234
DROP TRIGGER   trig3;
 
235
DROP PROCEDURE proc4;
 
236
DROP FUNCTION  func5;
 
237
DROP PREPARE   prep6;
 
238
DROP TABLE t1, t2, t3, trigger_table, trigger_table2;
 
239
#
 
240
# BUG#34768 - nondeterministic INSERT using LIMIT logged in stmt mode if
 
241
#             binlog_format=mixed
 
242
#
 
243
CREATE TABLE t1(a INT, b INT, KEY(a), PRIMARY KEY(b));
 
244
INSERT INTO t1 SELECT * FROM t1 LIMIT 1;
 
245
REPLACE INTO t1 SELECT * FROM t1 LIMIT 1;
 
246
UPDATE t1 SET a=1 LIMIT 1;
 
247
DELETE FROM t1 LIMIT 1;
 
248
delimiter |;
 
249
CREATE PROCEDURE p1()
 
250
BEGIN
 
251
  INSERT INTO t1 SELECT * FROM t1 LIMIT 1;
 
252
  REPLACE INTO t1 SELECT * FROM t1 LIMIT 1;
 
253
  UPDATE t1 SET a=1 LIMIT 1;
 
254
  DELETE FROM t1 LIMIT 1;
 
255
END|
 
256
delimiter ;|
 
257
CALL p1();
 
258
DROP PROCEDURE p1;
 
259
DROP TABLE t1;