~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/extra/rpl_tests/rpl_row_tabledefs.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
# Test how replication of tables work when the definition on the
 
2
# master and slave differs.
 
3
 
 
4
# Consider making these part of the basic RBR tests.
 
5
 
 
6
connection master;
 
7
--disable_warnings
 
8
--disable_query_log
 
9
DROP TABLE IF EXISTS t1_int,t1_bit,t1_char,t1_nodef;
 
10
DROP TABLE IF EXISTS t2,t3,t4,t5,t6,t9;
 
11
--enable_query_log
 
12
--enable_warnings
 
13
sync_slave_with_master;
 
14
STOP SLAVE;
 
15
SET @my_sql_mode= @@global.sql_mode;
 
16
SET GLOBAL SQL_MODE='STRICT_ALL_TABLES';
 
17
START SLAVE;
 
18
 
 
19
connection master;
 
20
eval CREATE TABLE t1_int (a INT PRIMARY KEY, b INT) ENGINE=$engine_type;
 
21
eval CREATE TABLE t1_bit (a INT PRIMARY KEY, b INT) ENGINE=$engine_type;
 
22
eval CREATE TABLE t1_char (a INT PRIMARY KEY, b INT) ENGINE=$engine_type;
 
23
eval CREATE TABLE t1_nodef (a INT PRIMARY KEY, b INT) ENGINE=$engine_type;
 
24
eval CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=$engine_type;
 
25
eval CREATE TABLE t3 (a INT PRIMARY KEY, b INT) ENGINE=$engine_type;
 
26
eval CREATE TABLE t4 (a INT) ENGINE=$engine_type;
 
27
eval CREATE TABLE t5 (a INT, b INT, c INT) ENGINE=$engine_type;
 
28
eval CREATE TABLE t6 (a INT, b INT, c INT) ENGINE=$engine_type;
 
29
eval CREATE TABLE t7 (a INT NOT NULL) ENGINE=$engine_type;
 
30
eval CREATE TABLE t8 (a INT NOT NULL) ENGINE=$engine_type;
 
31
 
 
32
# Table used to detect that slave is running
 
33
eval CREATE TABLE t9 (a INT) ENGINE=$engine_type;
 
34
 
 
35
sync_slave_with_master;
 
36
 
 
37
# On the slave, we add one INT column last in table 't1_int',
 
38
ALTER TABLE t1_int ADD x INT DEFAULT 42;
 
39
# ... and add BIT columns last in table 't1_bit' to ensure that we
 
40
# have at least one extra null byte on the slave,
 
41
ALTER TABLE t1_bit
 
42
  ADD x BIT(3) DEFAULT b'011',
 
43
  ADD y BIT(5) DEFAULT b'10101',
 
44
  ADD z BIT(2) DEFAULT b'10';
 
45
# ... and add one CHAR column last in table 't1_char',
 
46
ALTER TABLE t1_char ADD x CHAR(20) DEFAULT 'Just a test';
 
47
# ... and add one non-nullable INT column last in table 't1_text'
 
48
#     with no default,
 
49
ALTER TABLE t1_nodef ADD x INT NOT NULL, ADD y INT NOT NULL, ADD z INT NOT NULL;
 
50
# ... and remove the last column in t2
 
51
ALTER TABLE t2 DROP b;
 
52
# ... change the type of the single column in table 't4'
 
53
ALTER TABLE t4 MODIFY a FLOAT;
 
54
# ... change the type of the middle column of table 't5'
 
55
ALTER TABLE t5 MODIFY b FLOAT;
 
56
# ... change the type of the last column of table 't6'
 
57
ALTER TABLE t6 MODIFY c FLOAT;
 
58
 
 
59
# ... add one byte worth of null bytes to the table on the slave
 
60
ALTER TABLE t7 ADD e1 INT, ADD e2 INT, ADD e3 INT, ADD e4 INT,
 
61
               ADD e5 INT, ADD e6 INT, ADD e7 INT, ADD e8 INT;
 
62
 
 
63
# ... add 8 columns that are nullable: t8 will not be entirely
 
64
#     nullable and have no null bits (just an X bit)
 
65
ALTER TABLE t8 ADD e1 INT NOT NULL DEFAULT 0, ADD e2 INT NOT NULL DEFAULT 0,
 
66
               ADD e3 INT NOT NULL DEFAULT 0, ADD e4 INT NOT NULL DEFAULT 0,
 
67
               ADD e5 INT NOT NULL DEFAULT 0, ADD e6 INT NOT NULL DEFAULT 0,
 
68
               ADD e7 INT NOT NULL DEFAULT 0, ADD e8 INT NOT NULL DEFAULT 0;
 
69
        
 
70
# Insert some values for tables on slave side. These should not be
 
71
# modified when the row from the master is applied.
 
72
# since bug#31552/31609 idempotency is not default any longer. In order
 
73
# the following INSERTs to pass the mode is switched temprorarily
 
74
set @@global.slave_exec_mode= 'IDEMPOTENT';
 
75
 
 
76
# so the inserts are going to be overriden
 
77
INSERT INTO t1_int  VALUES (2, 4, 4711);
 
78
INSERT INTO t1_char VALUES (2, 4, 'Foo is a bar');
 
79
INSERT INTO t1_bit  VALUES (2, 4, b'101', b'11100', b'01');
 
80
 
 
81
--echo **** On Master ****
 
82
connection master;
 
83
INSERT INTO t1_int VALUES (1,2);
 
84
INSERT INTO t1_int VALUES (2,5);
 
85
INSERT INTO t1_bit VALUES (1,2);
 
86
INSERT INTO t1_bit VALUES (2,5);
 
87
INSERT INTO t1_char VALUES (1,2);
 
88
INSERT INTO t1_char VALUES (2,5);
 
89
SELECT * FROM t1_int ORDER BY a;
 
90
SELECT * FROM t1_bit ORDER BY a;
 
91
SELECT * FROM t1_char ORDER BY a;
 
92
--echo **** On Slave ****
 
93
sync_slave_with_master;
 
94
set @@global.slave_exec_mode= default;
 
95
 
 
96
SELECT a,b,x FROM t1_int ORDER BY a;
 
97
SELECT a,b,HEX(x),HEX(y),HEX(z) FROM t1_bit ORDER BY a;
 
98
SELECT a,b,x FROM t1_char ORDER BY a;
 
99
 
 
100
--echo **** On Master ****
 
101
connection master;
 
102
UPDATE t1_int  SET b=2*b WHERE a=2;
 
103
UPDATE t1_char SET b=2*b WHERE a=2;
 
104
UPDATE t1_bit  SET b=2*b WHERE a=2;
 
105
SELECT * FROM t1_int ORDER BY a;
 
106
SELECT * FROM t1_bit ORDER BY a;
 
107
SELECT * FROM t1_char ORDER BY a;
 
108
--echo **** On Slave ****
 
109
sync_slave_with_master;
 
110
SELECT a,b,x FROM t1_int ORDER BY a;
 
111
SELECT a,b,HEX(x),HEX(y),HEX(z) FROM t1_bit ORDER BY a;
 
112
SELECT a,b,x FROM t1_char ORDER BY a;
 
113
 
 
114
# Each of these inserts should generate an error and stop the slave
 
115
 
 
116
connection master;
 
117
INSERT INTO t9 VALUES (2);
 
118
sync_slave_with_master;
 
119
# Now slave is guaranteed to be running
 
120
connection master;
 
121
INSERT INTO t1_nodef VALUES (1,2);
 
122
connection slave;
 
123
--source include/wait_for_slave_sql_to_stop.inc
 
124
--replace_result $MASTER_MYPORT MASTER_PORT
 
125
--replace_column 1 # 4 # 7 # 8 # 9 # 20 <Last_Error> 22 # 23 # 33 # 36 <Last_IO_Error> 38 <Last_SQL_Error>
 
126
--query_vertical SHOW SLAVE STATUS
 
127
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 
128
START SLAVE;
 
129
 
 
130
#
 
131
# Replicating to tables with fewer columns at the end works as of WL#3228
 
132
#
 
133
connection master;
 
134
INSERT INTO t9 VALUES (2);
 
135
sync_slave_with_master;
 
136
# Now slave is guaranteed to be running
 
137
connection master;
 
138
--echo **** On Master ****
 
139
INSERT INTO t2 VALUES (2,4);
 
140
SELECT * FROM t2;
 
141
sync_slave_with_master;
 
142
--echo **** On Slave ****
 
143
SELECT * FROM t2;
 
144
--replace_result $MASTER_MYPORT MASTER_PORT
 
145
--replace_column 1 # 4 # 7 # 8 # 9 # 20 <Last_Error> 22 # 23 # 33 # 36 <Last_IO_Error> 38 <Last_SQL_Error>
 
146
--query_vertical SHOW SLAVE STATUS
 
147
 
 
148
connection master;
 
149
INSERT INTO t9 VALUES (4);
 
150
sync_slave_with_master;
 
151
# Now slave is guaranteed to be running
 
152
connection master;
 
153
INSERT INTO t4 VALUES (4);
 
154
connection slave;
 
155
--source include/wait_for_slave_sql_to_stop.inc
 
156
--replace_result $MASTER_MYPORT MASTER_PORT
 
157
--replace_column 1 # 4 # 7 # 8 # 9 # 20 <Last_Error> 22 # 23 # 33 # 36 <Last_IO_Error> 38 <Last_SQL_Error>
 
158
--query_vertical SHOW SLAVE STATUS
 
159
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 
160
START SLAVE;
 
161
 
 
162
connection master;
 
163
INSERT INTO t9 VALUES (5);
 
164
sync_slave_with_master;
 
165
# Now slave is guaranteed to be running
 
166
connection master;
 
167
INSERT INTO t5 VALUES (5,10,25);
 
168
connection slave;
 
169
--source include/wait_for_slave_sql_to_stop.inc
 
170
--replace_result $MASTER_MYPORT MASTER_PORT
 
171
--replace_column 1 # 4 # 7 # 8 # 9 # 20 <Last_Error> 22 # 23 # 33 # 36 <Last_IO_Error> 38 <Last_SQL_Error>
 
172
--query_vertical SHOW SLAVE STATUS
 
173
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 
174
START SLAVE;
 
175
 
 
176
connection master;
 
177
INSERT INTO t9 VALUES (6);
 
178
sync_slave_with_master;
 
179
# Now slave is guaranteed to be running
 
180
connection master;
 
181
INSERT INTO t6 VALUES (6,12,36);
 
182
connection slave;
 
183
--source include/wait_for_slave_sql_to_stop.inc
 
184
--replace_result $MASTER_MYPORT MASTER_PORT
 
185
--replace_column 1 # 4 # 7 # 8 # 9 # 20 <Last_Error> 22 # 23 # 33 # 36 <Last_IO_Error> 38 <Last_SQL_Error>
 
186
--query_vertical SHOW SLAVE STATUS
 
187
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 
188
START SLAVE;
 
189
 
 
190
connection master;
 
191
INSERT INTO t9 VALUES (6);
 
192
sync_slave_with_master;
 
193
--replace_result $SLAVE_MYPORT SLAVE_PORT
 
194
--replace_column 1 # 4 # 7 # 8 # 9 # 20 <Last_Error> 22 # 23 # 33 # 36 <Last_IO_Error> 38 <Last_SQL_Error>
 
195
--query_vertical SHOW SLAVE STATUS
 
196
 
 
197
# Testing some tables extra field that can be null and cannot be null
 
198
# (but have default values)
 
199
 
 
200
connection master;
 
201
INSERT INTO t7 VALUES (1),(2),(3);
 
202
INSERT INTO t8 VALUES (1),(2),(3);
 
203
SELECT * FROM t7 ORDER BY a;
 
204
SELECT * FROM t8 ORDER BY a;
 
205
sync_slave_with_master;
 
206
SELECT * FROM t7 ORDER BY a;
 
207
SELECT * FROM t8 ORDER BY a;
 
208
 
 
209
# We will now try to update and then delete a row on the master where
 
210
# the extra field on the slave does not have a default value. This
 
211
# update should not generate an error even though there is no default
 
212
# for the extra column. 
 
213
 
 
214
--echo **** On Master ****
 
215
connection master;
 
216
TRUNCATE t1_nodef;
 
217
SET SQL_LOG_BIN=0;
 
218
INSERT INTO t1_nodef VALUES (1,2);
 
219
INSERT INTO t1_nodef VALUES (2,4);
 
220
SET SQL_LOG_BIN=1;
 
221
sync_slave_with_master;
 
222
 
 
223
--echo **** On Slave ****
 
224
connection slave;
 
225
INSERT INTO t1_nodef VALUES (1,2,3,4,5);
 
226
INSERT INTO t1_nodef VALUES (2,4,6,8,10);
 
227
 
 
228
--echo **** On Master ****
 
229
connection master;
 
230
UPDATE t1_nodef SET b=2*b WHERE a=1;
 
231
SELECT * FROM t1_nodef ORDER BY a;
 
232
 
 
233
--echo **** On Slave ****
 
234
sync_slave_with_master;
 
235
SELECT * FROM t1_nodef ORDER BY a;
 
236
 
 
237
--echo **** On Master ****
 
238
connection master;
 
239
DELETE FROM t1_nodef WHERE a=2;
 
240
SELECT * FROM t1_nodef ORDER BY a;
 
241
 
 
242
--echo **** On Slave ****
 
243
sync_slave_with_master;
 
244
SELECT * FROM t1_nodef ORDER BY a;
 
245
 
 
246
--echo **** Cleanup ****
 
247
connection master;
 
248
--disable_warnings
 
249
DROP TABLE IF EXISTS t1_int,t1_bit,t1_char,t1_nodef;
 
250
DROP TABLE IF EXISTS t2,t3,t4,t5,t6,t7,t8,t9;
 
251
--enable_warnings
 
252
sync_slave_with_master;
 
253
 
 
254
# Restore sql_mode
 
255
SET @@global.sql_mode= @my_sql_mode;