1
################# extra/rpl_tests/rpl_ddl.test ########################
3
# DDL statements (sometimes with implicit COMMIT) and other stuff #
4
# executed on the master and it's propagation into the slave. #
7
# $engine_type -- storage engine to be tested/used for the #
8
# permanent tables within the master #
9
# $temp_engine_type -- storage engine which supports TEMPORARY #
10
# tables <> $engine_type #
11
# $temp_engine_type must point to an all #
12
# time available storage engine #
13
# 2007-02 MySQL 5.1 MyISAM and MEMORY only #
14
# $show_binlog -- print binlog entries #
15
# 0 - no (default) + fits to the file with #
17
# 1 - yes (important for debugging) #
18
# This variable is used within #
19
# include/rpl_stmt_seq.inc. #
20
# $manipulate -- Manipulation of the binary logs #
22
# 1 - so that the output of SHOW BINLOG #
23
# EVENTS IN <current log> contains only #
24
# commands of the current test sequence #
25
# This is especially useful, if the #
26
# $show_binlog is set to 1 and many #
27
# subtest are executed. #
28
# This variable is used within #
29
# include/rpl_stmt_seq.inc. #
30
# have to be set before sourcing this script. #
32
# General assumption about the ideal replication behaviour: #
33
# Whatever on the master is executed the content of the slave must #
34
# be in sync with it. #
36
# Tests of special interest: #
37
# a) Which DDL commands cause an implicit COMMIT ? #
38
# This is also of interest outside of replication. #
39
# b) Transactions modifying table content ending with #
40
# - explicit COMMIT or ROLLBACK #
41
# - implicit COMMIT because the connection to the master #
42
# executed a corresponding DDL statement or runs in #
44
# - something similar to "implicit COMMIT" if the storage #
45
# engine (master) is not transactional #
46
# c) Command which change no data like SELECT or SHOW #
47
# They do not change anything within the master but #
48
# this must be also valid for the slave. #
50
#######################################################################
53
# 2007-02-12 ML: - slave needs AUTOCOMMIT = 1, because we want to check only
54
# the propagation of actions of the master connection.
55
# - replace comments via SQL by "--echo ..."
56
# - remove some bugs within the testscripts
57
# - remove the use of include/rpl_stmt_seq2.inc
61
# 2006-11-15 Lars: Matthias (ML) is the "owner" of this test case.
62
# So, please get him to review it whenever you want to
65
# PLEASE BE CAREFUL, WHEN MODIFYING THE TESTS !!
67
# Typical test architecture (--> include/rpl_stmt_seq.inc)
68
# --------------------------------------------------------
69
# 1. Master (no AUTOCOMMIT!): INSERT INTO mysqltest1.t1 without commit
70
# 2. Master and slave: Check the content of mysqltest1.t1
71
# 3. Master (no AUTOCOMMIT!): EXECUTE the statement to be tested
72
# 4. Master and slave: Check the content of mysqltest1.t1
73
# 5. Master (no AUTOCOMMIT!): ROLLBACK
74
# 6. Master and slave: Check the content of mysqltest1.t1
75
# If the previous into mysqltest1.t1 inserted row is visible,
76
# than the statement to be tested caused an explicit COMMIT
77
# (statement = COMMIT) or an implicit COMMIT (example CREATE TABLE).
78
# If the previous into mysqltest1.t1 inserted row is not visible,
79
# than the statement to be tested caused either an explicit ROLLBACK
80
# (statement = ROLLBACK), an implicit ROLLBACK (deadlock etc. but
81
# not tested here) or it does not cause any transaction end.
86
# 1. Any use of mysqltest1.t1 within the statement to be tested must be
87
# avoided if possible. The only known exception is around LOCK TABLE.
89
# 2. The test logics needs for
90
# master connection: AUTOCOMMIT = 0
91
# slave connection: AUTOCOMMIT = 1
92
# The master connection is the actor and the slave connection is
93
# only an observer. I.e. the slave connection must not influence
94
# the activities of master connection.
96
# 3. !All! objects to be dropped, renamed, altered ... must be created
97
# before the tests start.
98
# --> less switching of AUTOCOMMIT mode on master side.
100
# 4. Never use a test object, which was direct or indirect affected by a
101
# preceeding test sequence again.
102
# If one preceeding test sequence hits a (sometimes not visible,
103
# because the sql error code of the statement might be 0) bug
104
# and these rules are ignored, a following test sequence might earn ugly
105
# effects like failing 'sync_slave_with_master', crashes of the slave or
106
# abort of the test case etc.. This means during analysis the first look
107
# points into a totally wrong area.
108
# Except table mysqltest1.t1 where ONLY DML is allowed.
110
# 5. This file is used in several tests (t/rpl_ddl_<whatever>.test).
111
# Please be aware that every change of the current file affects
112
# the results of these tests.
114
# ML: Some maybe banal hints:
115
# 1. The fact that we have here a master - slave replication does
116
# not cause that many general MySQL properties do not apply.
118
# The connection to the slave is just a simple session and not a however
119
# magic working "copy" of the master session or something similar.
120
# - TEMPORARY TABLES and @variables are session specific
121
# - the slave session cannot see these things of the master.
122
# 2. The slave connection must not call sync_slave_with_master.
123
# 3. SHOW STATUS SLAVE must be run within the slave connection.
124
# 4. Testcase analysis becomes much more comfortable if
125
# $show_binlog within include/rpl_stmt_seq.inc is set to 1.
128
###############################################################
130
###############################################################
131
# The sync_slave_with_master is needed to make the xids deterministic.
132
sync_slave_with_master;
135
--echo -------- switch to master -------
139
# 1. DROP all objects, which probably already exist, but must be created here
142
DROP DATABASE IF EXISTS mysqltest1;
143
DROP DATABASE IF EXISTS mysqltest2;
144
DROP DATABASE IF EXISTS mysqltest3;
147
# 2. CREATE all objects needed
148
# working database is mysqltest1
149
# working table (transactional!) is mysqltest1.t1
151
CREATE DATABASE mysqltest1;
152
CREATE DATABASE mysqltest2;
153
eval CREATE TABLE mysqltest1.t1 (f1 BIGINT) ENGINE=$engine_type;
154
INSERT INTO mysqltest1.t1 SET f1= 0;
155
eval CREATE TABLE mysqltest1.t2 (f1 BIGINT) ENGINE=$engine_type;
156
eval CREATE TABLE mysqltest1.t3 (f1 BIGINT) ENGINE=$engine_type;
157
eval CREATE TABLE mysqltest1.t4 (f1 BIGINT) ENGINE=$engine_type;
158
eval CREATE TABLE mysqltest1.t5 (f1 BIGINT) ENGINE=$engine_type;
159
eval CREATE TABLE mysqltest1.t6 (f1 BIGINT) ENGINE=$engine_type;
160
CREATE INDEX my_idx6 ON mysqltest1.t6(f1);
161
eval CREATE TABLE mysqltest1.t7 (f1 BIGINT) ENGINE=$engine_type;
162
INSERT INTO mysqltest1.t7 SET f1= 0;
163
eval CREATE TABLE mysqltest1.t8 (f1 BIGINT) ENGINE=$engine_type;
164
eval CREATE TABLE mysqltest1.t9 (f1 BIGINT) ENGINE=$engine_type;
165
eval CREATE TABLE mysqltest1.t10 (f1 BIGINT) ENGINE=$engine_type;
166
eval CREATE TABLE mysqltest1.t11 (f1 BIGINT) ENGINE=$engine_type;
167
eval CREATE TABLE mysqltest1.t12 (f1 BIGINT) ENGINE=$engine_type;
168
eval CREATE TABLE mysqltest1.t13 (f1 BIGINT) ENGINE=$engine_type;
169
eval CREATE TABLE mysqltest1.t14 (f1 BIGINT) ENGINE=$engine_type;
170
eval CREATE TABLE mysqltest1.t15 (f1 BIGINT) ENGINE=$engine_type;
171
eval CREATE TABLE mysqltest1.t16 (f1 BIGINT) ENGINE=$engine_type;
172
eval CREATE TABLE mysqltest1.t17 (f1 BIGINT) ENGINE=$engine_type;
173
eval CREATE TABLE mysqltest1.t18 (f1 BIGINT) ENGINE=$engine_type;
174
eval CREATE TABLE mysqltest1.t19 (f1 BIGINT) ENGINE=$engine_type;
175
eval CREATE TEMPORARY TABLE mysqltest1.t23 (f1 BIGINT) ENGINE=$temp_engine_type;
178
# 3. master sessions: never do AUTOCOMMIT
179
# slave sessions: do AUTOCOMMIT
183
sync_slave_with_master;
185
--echo -------- switch to slave --------
190
--echo -------- switch to master -------
194
# We don't want to abort the whole test if one statement sent
195
# to the server gets an error, because the following test
196
# sequences are nearly independend of the previous statements.
197
--disable_abort_on_error
199
###############################################################
200
# Banal case: commands which should never commit
201
# Just for checking if the test sequence is usable
202
###############################################################
204
let $my_stmt= SELECT 1;
205
let $my_master_commit= false;
206
let $my_slave_commit= false;
207
--source include/rpl_stmt_seq.inc
209
let $my_stmt= SELECT COUNT(*) FROM t1;
210
let $my_master_commit= false;
211
let $my_slave_commit= false;
212
--source include/rpl_stmt_seq.inc
214
###############################################################
215
# Banal case: (explicit) COMMIT and ROLLBACK
216
# Just for checking if the test sequence is usable
217
###############################################################
219
let $my_stmt= COMMIT;
220
let $my_master_commit= true;
221
let $my_slave_commit= true;
222
--source include/rpl_stmt_seq.inc
224
let $my_stmt= ROLLBACK;
225
let $my_master_commit= false;
226
let $my_slave_commit= false;
227
--source include/rpl_stmt_seq.inc
229
###############################################################
230
# Cases with commands very similar to COMMIT
231
###############################################################
233
let $my_stmt= SET AUTOCOMMIT=1;
234
let $my_master_commit= true;
235
let $my_slave_commit= true;
236
--source include/rpl_stmt_seq.inc
239
let $my_stmt= START TRANSACTION;
240
let $my_master_commit= true;
241
let $my_slave_commit= true;
242
--source include/rpl_stmt_seq.inc
245
let $my_master_commit= true;
246
let $my_slave_commit= true;
247
--source include/rpl_stmt_seq.inc
249
###############################################################
250
# Cases with (BASE) TABLES and (UPDATABLE) VIEWs
251
###############################################################
253
let $my_stmt= DROP TABLE mysqltest1.t2;
254
let $my_master_commit= true;
255
let $my_slave_commit= true;
256
--source include/rpl_stmt_seq.inc
257
SHOW TABLES LIKE 't2';
259
--echo -------- switch to slave --------
261
SHOW TABLES LIKE 't2';
263
--echo -------- switch to master -------
266
let $my_stmt= DROP TEMPORARY TABLE mysqltest1.t23;
267
let $my_master_commit= false;
268
let $my_slave_commit= false;
269
--source include/rpl_stmt_seq.inc
270
SHOW TABLES LIKE 't23';
272
--echo -------- switch to slave --------
274
SHOW TABLES LIKE 't23';
276
--echo -------- switch to master -------
279
let $my_stmt= RENAME TABLE mysqltest1.t3 to mysqltest1.t20;
280
let $my_master_commit= true;
281
let $my_slave_commit= true;
282
--source include/rpl_stmt_seq.inc
283
SHOW TABLES LIKE 't20';
285
--echo -------- switch to slave --------
287
SHOW TABLES LIKE 't20';
289
--echo -------- switch to master -------
292
let $my_stmt= ALTER TABLE mysqltest1.t4 ADD column f2 BIGINT;
293
let $my_master_commit= true;
294
let $my_slave_commit= true;
295
--source include/rpl_stmt_seq.inc
296
describe mysqltest1.t4;
298
--echo -------- switch to slave --------
300
describe mysqltest1.t4;
302
--echo -------- switch to master -------
305
let $my_stmt= CREATE TABLE mysqltest1.t21 (f1 BIGINT) ENGINE= $engine_type;
306
let $my_master_commit= true;
307
let $my_slave_commit= true;
308
--source include/rpl_stmt_seq.inc
313
let $my_stmt= CREATE TEMPORARY TABLE mysqltest1.t22 (f1 BIGINT) ENGINE=$temp_engine_type;
314
let $my_master_commit= false;
315
let $my_slave_commit= false;
316
--source include/rpl_stmt_seq.inc
318
let $my_stmt= TRUNCATE TABLE mysqltest1.t7;
319
let $my_master_commit= true;
320
let $my_slave_commit= true;
321
--source include/rpl_stmt_seq.inc
322
SELECT * FROM mysqltest1.t7;
323
sync_slave_with_master;
325
--echo -------- switch to slave --------
327
SELECT * FROM mysqltest1.t7;
329
--echo -------- switch to master -------
332
###############################################################
333
# Cases with LOCK/UNLOCK
334
###############################################################
337
# We have to LOCK mysqltest1.t1 here, though it violates the testing
339
# Mysql response in case without previous LOCK TABLES mysqltest1.t1
341
# SELECT MAX(...) FROM mysqltest1.t1 is
342
# ERROR HY000: Table 't1' was not locked with LOCK TABLES
343
let $my_stmt= LOCK TABLES mysqltest1.t1 WRITE, mysqltest1.t8 READ;
344
let $my_master_commit= true;
345
let $my_slave_commit= true;
346
--source include/rpl_stmt_seq.inc
350
let $my_stmt= UNLOCK TABLES;
351
let $my_master_commit= false;
352
let $my_slave_commit= false;
353
--source include/rpl_stmt_seq.inc
355
# With prior read locking
357
# This subtest generates an error since the rpl_stmt_seq.inc
358
# tries to insert into t1.
359
LOCK TABLES mysqltest1.t1 READ;
360
let $my_stmt= UNLOCK TABLES;
361
let $my_master_commit= false;
362
let $my_slave_commit= false;
363
--source include/rpl_stmt_seq.inc
365
# With prior write locking
366
LOCK TABLES mysqltest1.t1 WRITE, mysqltest1.t8 READ;
367
let $my_stmt= UNLOCK TABLES;
368
let $my_master_commit= true;
369
let $my_slave_commit= true;
370
--source include/rpl_stmt_seq.inc
372
###############################################################
374
###############################################################
376
let $my_stmt= DROP INDEX my_idx6 ON mysqltest1.t6;
377
let $my_master_commit= true;
378
let $my_slave_commit= true;
379
--source include/rpl_stmt_seq.inc
380
SHOW INDEX FROM mysqltest1.t6;
382
--echo -------- switch to slave --------
384
SHOW INDEX FROM mysqltest1.t6;
386
--echo -------- switch to master -------
389
let $my_stmt= CREATE INDEX my_idx5 ON mysqltest1.t5(f1);
390
let $my_master_commit= true;
391
let $my_slave_commit= true;
392
--source include/rpl_stmt_seq.inc
393
SHOW INDEX FROM mysqltest1.t5;
395
--echo -------- switch to slave --------
397
SHOW INDEX FROM mysqltest1.t5;
399
--echo -------- switch to master -------
402
###############################################################
403
# Cases with DATABASE
404
###############################################################
406
let $my_stmt= DROP DATABASE mysqltest2;
407
let $my_master_commit= true;
408
let $my_slave_commit= true;
409
--source include/rpl_stmt_seq.inc
410
SHOW DATABASES LIKE "mysqltest2";
412
--echo -------- switch to slave --------
414
SHOW DATABASES LIKE "mysqltest2";
416
--echo -------- switch to master -------
419
let $my_stmt= CREATE DATABASE mysqltest3;
420
let $my_master_commit= true;
421
let $my_slave_commit= true;
422
--source include/rpl_stmt_seq.inc
423
SHOW DATABASES LIKE "mysqltest3";
425
--echo -------- switch to slave --------
427
SHOW DATABASES LIKE "mysqltest3";
429
--echo -------- switch to master -------
434
###############################################################
435
# Cases with STORED PROCEDUREs
436
###############################################################
437
let $my_stmt= CREATE PROCEDURE p1() READS SQL DATA SELECT "this is p1";
438
let $my_master_commit= true;
439
let $my_slave_commit= true;
440
--source include/rpl_stmt_seq.inc
442
--replace_column 5 # 6 #
443
SHOW PROCEDURE STATUS LIKE 'p1';
445
--echo -------- switch to slave --------
447
--replace_column 5 # 6 #
448
SHOW PROCEDURE STATUS LIKE 'p1';
450
--echo -------- switch to master -------
454
let $my_stmt= ALTER PROCEDURE p1 COMMENT "I have been altered";
455
let $my_master_commit= true;
456
let $my_slave_commit= true;
457
--source include/rpl_stmt_seq.inc
459
--replace_column 5 # 6 #
460
SHOW PROCEDURE STATUS LIKE 'p1';
462
--echo -------- switch to slave --------
464
--replace_column 5 # 6 #
465
SHOW PROCEDURE STATUS LIKE 'p1';
467
--echo -------- switch to master -------
471
let $my_stmt= DROP PROCEDURE p1;
472
let $my_master_commit= true;
473
let $my_slave_commit= true;
474
--source include/rpl_stmt_seq.inc
476
SHOW PROCEDURE STATUS LIKE 'p1';
478
--echo -------- switch to slave --------
480
SHOW PROCEDURE STATUS LIKE 'p1';
482
--echo -------- switch to master -------
486
###############################################################
488
###############################################################
489
let $my_stmt= CREATE OR REPLACE VIEW v1 as select * from t1;
490
let $my_master_commit= true;
491
let $my_slave_commit= true;
492
--source include/rpl_stmt_seq.inc
495
--echo -------- switch to slave --------
499
--echo -------- switch to master -------
502
let $my_stmt= ALTER VIEW v1 AS select f1 from t1;
503
let $my_master_commit= true;
504
let $my_slave_commit= true;
505
--source include/rpl_stmt_seq.inc
508
--echo -------- switch to slave --------
512
--echo -------- switch to master -------
515
let $my_stmt= DROP VIEW IF EXISTS v1;
516
let $my_master_commit= true;
517
let $my_slave_commit= true;
518
--source include/rpl_stmt_seq.inc
522
--echo -------- switch to slave --------
527
--echo -------- switch to master -------
530
###############################################################
531
# Cases with TRIGGERs
532
###############################################################
533
let $my_stmt= CREATE TRIGGER trg1 BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1;
534
let $my_master_commit= true;
535
let $my_slave_commit= true;
536
--source include/rpl_stmt_seq.inc
539
--echo -------- switch to slave --------
543
--echo -------- switch to master -------
546
let $my_stmt= DROP TRIGGER trg1;
547
let $my_master_commit= true;
548
let $my_slave_commit= true;
549
--source include/rpl_stmt_seq.inc
552
--echo -------- switch to slave --------
556
--echo -------- switch to master -------
559
###############################################################
561
###############################################################
562
let $my_stmt= CREATE USER user1@localhost;
563
let $my_master_commit= true;
564
let $my_slave_commit= true;
565
--source include/rpl_stmt_seq.inc
566
SELECT user FROM mysql.user WHERE user = 'user1';
568
--echo -------- switch to slave --------
570
SELECT user FROM mysql.user WHERE user = 'user1';
572
--echo -------- switch to master -------
575
let $my_stmt= RENAME USER user1@localhost TO rename1@localhost;
576
let $my_master_commit= true;
577
let $my_slave_commit= true;
578
--source include/rpl_stmt_seq.inc
579
SELECT user FROM mysql.user WHERE user = 'rename1';
581
--echo -------- switch to slave --------
583
SELECT user FROM mysql.user WHERE user = 'rename1';
585
--echo -------- switch to master -------
588
let $my_stmt= DROP USER rename1@localhost;
589
let $my_master_commit= true;
590
let $my_slave_commit= true;
591
--source include/rpl_stmt_seq.inc
592
SELECT user FROM mysql.user WHERE user = 'rename1';
594
--echo -------- switch to slave --------
596
SELECT user FROM mysql.user WHERE user = 'rename1';
598
###############################################################
600
###############################################################
603
--echo -------- switch to master -------
605
DROP DATABASE mysqltest1;
606
# mysqltest2 was alreday DROPPED some tests before.
607
DROP DATABASE mysqltest3;
610
-- source include/master-slave-end.inc