1#
2# misc binlogging tests that do not require a slave running
3#
4
5-- source include/have_log_bin.inc
6-- source include/not_embedded.inc
7-- source include/have_innodb.inc
8-- source include/have_debug.inc
9
10RESET MASTER;
11
12create table t1 (a int) engine=innodb;
13create table t2 (a int) engine=innodb;
14begin;
15insert t1 values (5);
16commit;
17begin;
18insert t2 values (5);
19commit;
20# first COMMIT must be Query_log_event, second - Xid_log_event
21source include/show_binlog_events.inc;
22drop table t1,t2;
23
24#
25# binlog rotation after one big transaction
26#
27reset master;
28let $1=100;
29
30create table t1 (n int) engine=innodb;
31begin;
32--disable_query_log
33while ($1)
34{
35 eval insert into t1 values($1 + 4);
36 dec $1;
37}
38--enable_query_log
39commit;
40drop table t1;
41--source include/show_binlog_events.inc
42--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
43--source include/show_binlog_events.inc
44--let $binlog_file=
45
46#
47# Bug#22540 - Incorrect value in column End_log_pos of
48# SHOW BINLOG EVENTS using InnoDB
49#
50
51# the following tests will show that certain queries now return
52# absolute offsets (from binlog start, rather than relative to
53# the beginning of the current transaction).  under what
54# conditions it should be allowed / is sensible to put the
55# slider into the middle of a transaction is not our concern
56# here; we just guarantee that if and when it's done, the
57# user has valid offsets to use.  if the setter function still
58# wants to throw a "positioning into middle of transaction"
59# warning, that's its prerogative and handled elsewhere.
60
61set @ac = @@autocommit;
62
63# first show this to work for SHOW BINLOG EVENTS
64
65set autocommit= 0;
66reset master;
67create table t1(n int) engine=innodb;
68begin;
69insert into t1 values (1);
70insert into t1 values (2);
71insert into t1 values (3);
72commit;
73drop table t1;
74--source include/show_binlog_events.inc
75
76# now show that nothing breaks if we need to read from the cache more
77# than once, resulting in split event-headers
78
79set @bcs = @@binlog_cache_size;
80set global binlog_cache_size=4096;
81reset master;
82
83create table t1 (a int, b char(255)) engine=innodb;
84
85flush status;
86show status like "binlog_cache_use";
87
88let $1=100;
89disable_query_log;
90begin;
91while ($1)
92{
93 eval insert into t1 values( $1, 'just to fill void to make transaction occupying at least two buffers of the trans cache' );
94 dec $1;
95}
96commit;
97--echo *** the following must show the counter value = 1 ***
98show status like "binlog_cache_use";
99enable_query_log;
100
101--source include/show_binlog_events.inc
102
103drop table t1;
104
105set global binlog_cache_size=@bcs;
106set session autocommit = @ac;
107
108#
109# Bug#33798: prepared statements improperly handle large unsigned ints
110#
111--disable_warnings
112drop table if exists t1;
113--enable_warnings
114reset master;
115create table t1 (a bigint unsigned, b bigint(20) unsigned);
116prepare stmt from "insert into t1 values (?,?)";
117set @a= 9999999999999999;
118set @b= 14632475938453979136;
119execute stmt using @a, @b;
120deallocate prepare stmt;
121drop table t1;
122--source include/show_binlog_events.inc
123
124
125#
126# Bug #39182: Binary log producing incompatible character set query from
127# stored procedure.
128#
129reset master;
130CREATE DATABASE bug39182 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
131USE bug39182;
132CREATE TABLE t1 (a VARCHAR(255) COLLATE utf8_unicode_ci)
133  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
134
135DELIMITER //;
136
137CREATE PROCEDURE p1()
138BEGIN
139  DECLARE s1 VARCHAR(255);
140  SET s1= "test";
141  CREATE TEMPORARY TABLE tmp1
142    SELECT * FROM t1 WHERE a LIKE CONCAT("%", s1, "%");
143  SELECT
144    COLLATION(NAME_CONST('s1', _utf8'test')) c1,
145    COLLATION(NAME_CONST('s1', _utf8'test' COLLATE utf8_unicode_ci)) c2,
146    COLLATION(s1) c3,
147    COERCIBILITY(NAME_CONST('s1', _utf8'test')) d1,
148    COERCIBILITY(NAME_CONST('s1', _utf8'test' COLLATE utf8_unicode_ci)) d2,
149    COERCIBILITY(s1) d3;
150  DROP TEMPORARY TABLE tmp1;
151END//
152
153DELIMITER ;//
154
155CALL p1();
156source include/show_binlog_events.inc;
157
158DROP PROCEDURE p1;
159DROP TABLE t1;
160DROP DATABASE bug39182;
161USE test;
162
163#
164# Bug#35383: binlog playback and replication breaks due to
165# name_const substitution
166#
167DELIMITER //;
168CREATE PROCEDURE p1(IN v1 INT)
169BEGIN
170  CREATE TABLE t1 SELECT v1;
171  DROP TABLE t1;
172END//
173CREATE PROCEDURE p2()
174BEGIN
175  DECLARE v1 INT;
176  CREATE TABLE t1 SELECT v1+1;
177  DROP TABLE t1;
178END//
179CREATE PROCEDURE p3(IN v1 INT)
180BEGIN
181  CREATE TABLE t1 SELECT 1 FROM DUAL WHERE v1!=0;
182  DROP TABLE t1;
183END//
184CREATE PROCEDURE p4(IN v1 INT)
185BEGIN
186  DECLARE v2 INT;
187  CREATE TABLE t1 SELECT 1, v1, v2;
188  DROP TABLE t1;
189  CREATE TABLE t1 SELECT 1, v1+1, v2;
190  DROP TABLE t1;
191END//
192DELIMITER ;//
193
194CALL p1(1);
195CALL p2();
196CALL p3(0);
197CALL p4(0);
198DROP PROCEDURE p1;
199DROP PROCEDURE p2;
200DROP PROCEDURE p3;
201DROP PROCEDURE p4;
202
203--echo End of 5.0 tests
204
205# Test of a too big SET INSERT_ID: see if the truncated value goes
206# into binlog (right), or the too big value (wrong); we look at the
207# binlog further down with SHOW BINLOG EVENTS.
208reset master;
209create table t1 (id tinyint auto_increment primary key);
210set insert_id=128;
211insert ignore into t1 values(null);
212select * from t1;
213drop table t1;
214
215# bug#22027
216create table t1 (a int);
217create table if not exists t2 select * from t1;
218
219# bug#22762
220create temporary table tt1 (a int);
221create table if not exists t3 like tt1;
222
223# BUG#25091 (A DELETE statement to mysql database is not logged with
224# ROW mode format): Checking that some basic operations on tables in
225# the mysql database is replicated even when the current database is
226# 'mysql'.
227
228--disable_warnings
229USE mysql;
230INSERT IGNORE INTO user SET host='localhost', user='@#@', authentication_string=password('Just a test');
231UPDATE user SET authentication_string=password('Another password') WHERE host='localhost' AND user='@#@';
232DELETE FROM user WHERE host='localhost' AND user='@#@';
233--enable_warnings
234
235use test;
236
237# Show binlog events on a different connection because it calls
238# `SELECT UUID()` internally, which is marked unsafe. Since there is
239# an open temporary table, this causes the current connection to log
240# subsequent statements in row format.
241connect (other,localhost,root,,test);
242connection other;
243source include/show_binlog_events.inc;
244connection default;
245disconnect other;
246
247drop table t1,t2,t3,tt1;
248
249#Bug #26079 max_binlog_size + innodb = not make new binlog and hang server
250# server should not hang, binlog must rotate in the end
251reset master;
252--disable_warnings
253drop table if exists t3;
254--enable_warnings
255create table t3 (a int(11) NOT NULL AUTO_INCREMENT, b text, PRIMARY KEY (a) ) engine=innodb;
256--let $binlog_file1= query_get_value(SHOW MASTER STATUS, File, 1)
257--echo File $binlog_file1
258let $it=4;
259while ($it)
260{
261insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
262dec $it;
263}
264--let $binlog_file2= query_get_value(SHOW MASTER STATUS, File, 1)
265--echo *** show new binlog index after rotating ***
266--echo File $binlog_file2
267drop table t3;
268
269--echo #
270--echo # Bug #45998: database crashes when running "create as select"
271--echo #
272CREATE DATABASE test1;
273USE test1;
274DROP DATABASE test1;
275CREATE TABLE test.t1(a int);
276INSERT INTO test.t1 VALUES (1), (2);
277CREATE TABLE test.t2 SELECT * FROM test.t1;
278USE test;
279DROP TABLES t1, t2;
280
281#
282# Bug#46640
283# This test verifies if the server_id stored in the "format
284# description BINLOG statement" will override the server_id
285# of the server executing the statements.
286#
287
288connect (fresh,localhost,root,,test);
289connection fresh;
290
291RESET MASTER;
292CREATE TABLE t1 (a INT PRIMARY KEY);
293
294# Format description event, with server_id = 10;
295BINLOG '
2963u9kSA8KAAAAZgAAAGoAAAABAAQANS4xLjM1LW1hcmlhLWJldGExLWRlYnVnLWxvZwAAAAAAAAAA
297AAAAAAAAAAAAAAAAAADe72RIEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
298';
299
300# What server_id is logged for a statement? Should be our own, not the
301# one from the format description event.
302INSERT INTO t1 VALUES (1);
303
304# INSERT INTO t1 VALUES (2), with server_id=20. Check that this is logged
305# with our own server id, not the 20 from the BINLOG statement.
306BINLOG '
3073u9kSBMUAAAAKQAAAJEBAAAAABoAAAAAAAAABHRlc3QAAnQxAAEDAAA=
3083u9kSBcUAAAAIgAAALMBAAAQABoAAAAAAAEAAf/+AgAAAA==
309';
310
311# Show binlog events to check that server ids are correct.
312--let $show_binlog_events_mask_columns= 1,2,5
313--source include/show_binlog_events.inc
314
315DROP TABLE t1;
316
317--echo
318--echo # BUG#54903 BINLOG statement toggles session variables
319--echo # ----------------------------------------------------------------------
320--echo # This test verify that BINLOG statement doesn't change current session's
321--echo # variables foreign_key_checks and unique_checks.
322--echo
323CREATE TABLE t1 (c1 INT KEY);
324
325SET @@SESSION.foreign_key_checks= ON;
326SET @@SESSION.unique_checks= ON;
327
328--echo # INSERT INTO t1 VALUES (1)
329--echo # foreign_key_checks=0 and unique_checks=0
330BINLOG '
331dfLtTBMBAAAAKQAAANcAAAAAABcAAAAAAAEABHRlc3QAAnQxAAEDAAE=
332dfLtTBcBAAAAIgAAAPkAAAAAABcAAAAAAAcAAf/+AQAAAA==
333';
334
335SELECT * FROM t1;
336--echo # Their values should be ON
337SHOW SESSION VARIABLES LIKE "%_checks";
338
339--echo
340SET @@SESSION.foreign_key_checks= OFF;
341SET @@SESSION.unique_checks= OFF;
342
343--echo # INSERT INTO t1 VALUES(2)
344--echo # foreign_key_checks=1 and unique_checks=1
345BINLOG '
346dfLtTBMBAAAAKQAAAKsBAAAAABcAAAAAAAEABHRlc3QAAnQxAAEDAAE=
347dfLtTBcBAAAAIgAAAM0BAAAAABcAAAAAAAEAAf/+AgAAAA==
348';
349
350SELECT * FROM t1;
351--echo # Their values should be OFF
352SHOW SESSION VARIABLES LIKE "%_checks";
353
354--echo # INSERT INTO t1 VALUES(2)
355--echo # foreign_key_checks=1 and unique_checks=1
356--echo # It should not change current session's variables, even error happens
357call mtr.add_suppression("Slave SQL.*Could not execute Write_rows_v1 event on table test.t1; Duplicate entry .2. for key .PRIMARY., Error_code: 1062");
358--error 1062
359BINLOG '
360dfLtTBMBAAAAKQAAAKsBAAAAABcAAAAAAAEABHRlc3QAAnQxAAEDAAE=
361dfLtTBcBAAAAIgAAAM0BAAAAABcAAAAAAAEAAf/+AgAAAA==
362';
363
364SELECT * FROM t1;
365--echo # Their values should be OFF
366SHOW SESSION VARIABLES LIKE "%_checks";
367
368DROP TABLE t1;
369
370disconnect fresh;
371
372