~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/extra/rpl_tests/rpl_row_basic.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
#
 
2
# Basic tests of row-level logging
 
3
#
 
4
 
 
5
#
 
6
# First we test tables with only an index.
 
7
#
 
8
 
 
9
eval CREATE TABLE t1 (C1 CHAR(1), C2 CHAR(1), INDEX (C1)$extra_index_t1) ENGINE = $type ;
 
10
SELECT * FROM t1;
 
11
sync_slave_with_master;
 
12
SELECT * FROM t1;
 
13
 
 
14
# Testing insert
 
15
connection master;
 
16
INSERT INTO t1 VALUES ('A','B'), ('X','Y'), ('X','X');
 
17
INSERT INTO t1 VALUES ('A','C'), ('X','Z'), ('A','A');
 
18
SELECT * FROM t1 ORDER BY C1,C2;
 
19
sync_slave_with_master;
 
20
SELECT * FROM t1 ORDER BY C1,C2;
 
21
 
 
22
# Testing delete
 
23
# Observe that are several rows having the value for the index but only one
 
24
# should be deleted.
 
25
connection master;
 
26
DELETE FROM t1 WHERE C1 = C2;
 
27
SELECT * FROM t1 ORDER BY C1,C2;
 
28
sync_slave_with_master;
 
29
SELECT * FROM t1 ORDER BY C1,C2;
 
30
 
 
31
#
 
32
# Testing update.
 
33
# Note that we have a condition on a column that is not part of the index for
 
34
# the table. The right row should be updated nevertheless.
 
35
#
 
36
connection master;
 
37
UPDATE t1 SET C2 = 'I' WHERE C1 = 'A' AND C2 = 'C';
 
38
SELECT * FROM t1 ORDER BY C1,C2;
 
39
sync_slave_with_master;
 
40
SELECT * FROM t1 ORDER BY C1,C2;
 
41
 
 
42
# Testing update with a condition that does not match any rows, but
 
43
# which has a match for the index.
 
44
connection master;
 
45
UPDATE t1 SET c2 = 'Q' WHERE c1 = 'A' AND c2 = 'N';
 
46
SELECT * FROM t1 ORDER BY c1,c2;
 
47
sync_slave_with_master;
 
48
SELECT * FROM t1 ORDER BY c1,c2;
 
49
 
 
50
#
 
51
# Testing table with primary key
 
52
#
 
53
connection master;
 
54
eval CREATE TABLE t2 (c1 INT, c12 char(1), c2 INT, PRIMARY KEY (c1)) ENGINE = $type ;
 
55
INSERT INTO t2
 
56
  VALUES (1,'A',2),  (2,'A',4),  (3,'A',9),  (4,'A',15), (5,'A',25),
 
57
         (6,'A',35), (7,'A',50), (8,'A',64), (9,'A',81);
 
58
SELECT * FROM t2 ORDER BY c1,c2;
 
59
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
60
sync_slave_with_master;
 
61
SELECT * FROM t2 ORDER BY c1,c2;
 
62
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
63
 
 
64
connection master;
 
65
UPDATE t2 SET c2 = c1*c1 WHERE c2 != c1*c1;
 
66
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
67
sync_slave_with_master;
 
68
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
69
 
 
70
# Testing update with a condition that does not match any rows, but
 
71
# which has a match for the primary key.
 
72
connection master;
 
73
UPDATE t2 SET c12 = 'Q' WHERE c1 = 1 AND c2 = 999;
 
74
SELECT * FROM t2 ORDER BY c1,c2;
 
75
sync_slave_with_master;
 
76
SELECT * FROM t2 ORDER BY c1,c2;
 
77
 
 
78
connection master;
 
79
DELETE FROM t2 WHERE c1 % 4 = 0;
 
80
SELECT * FROM t2 ORDER BY c1,c2;
 
81
sync_slave_with_master;
 
82
SELECT * FROM t2 ORDER BY c1,c2;
 
83
 
 
84
connection master;
 
85
UPDATE t2 SET c12='X';
 
86
 
 
87
#
 
88
# Testing table with a multi-column primary key.
 
89
#
 
90
connection master;
 
91
eval CREATE TABLE t3 (C1 CHAR(1), C2 CHAR(1), pk1 INT, C3 CHAR(1), pk2 INT, PRIMARY KEY (pk1,pk2)) ENGINE = $type ;
 
92
 
 
93
INSERT INTO t3 VALUES ('A','B',1,'B',1), ('X','Y',2,'B',1), ('X','X',3,'B',1);
 
94
INSERT INTO t3 VALUES ('A','C',1,'B',2), ('X','Z',2,'B',2), ('A','A',3,'B',2);
 
95
SELECT * FROM t3 ORDER BY C1,C2;
 
96
sync_slave_with_master;
 
97
SELECT * FROM t3 ORDER BY C1,C2;
 
98
 
 
99
connection master;
 
100
DELETE FROM t3 WHERE C1 = C2;
 
101
SELECT * FROM t3 ORDER BY C1,C2;
 
102
sync_slave_with_master;
 
103
SELECT * FROM t3 ORDER BY C1,C2;
 
104
 
 
105
connection master;
 
106
UPDATE t3 SET C2 = 'I' WHERE C1 = 'A' AND C2 = 'C';
 
107
SELECT * FROM t3 ORDER BY C1,C2;
 
108
sync_slave_with_master;
 
109
SELECT * FROM t3 ORDER BY C1,C2;
 
110
 
 
111
#
 
112
# Testing table without index or primary key
 
113
#
 
114
connection master;
 
115
eval CREATE TABLE t6 (C1 CHAR(1), C2 CHAR(1), C3 INT$extra_index_t6) ENGINE = $type;
 
116
 
 
117
# Testing insert
 
118
INSERT INTO t6 VALUES ('A','B',1), ('X','Y',2), ('X','X',3);
 
119
INSERT INTO t6 VALUES ('A','C',4), ('X','Z',5), ('A','A',6);
 
120
SELECT * FROM t6 ORDER BY C3;
 
121
sync_slave_with_master;
 
122
SELECT * FROM t6 ORDER BY C3;
 
123
 
 
124
# Testing delete
 
125
# Observe that are several rows having the value for the index but only one
 
126
# should be deleted.
 
127
connection master;
 
128
DELETE FROM t6 WHERE C1 = C2;
 
129
SELECT * FROM t6 ORDER BY C3;
 
130
sync_slave_with_master;
 
131
SELECT * FROM t6 ORDER BY C3;
 
132
 
 
133
#
 
134
# Testing update.
 
135
# Note that we have a condition on a column that is not part of the index for
 
136
# the table. The right row should be updated nevertheless.
 
137
#
 
138
connection master;
 
139
UPDATE t6 SET C2 = 'I' WHERE C1 = 'A' AND C2 = 'C';
 
140
SELECT * FROM t6 ORDER BY C3;
 
141
sync_slave_with_master;
 
142
SELECT * FROM t6 ORDER BY C3;
 
143
 
 
144
# now mixing the 3 tables without begin/commit
 
145
connection master;
 
146
eval CREATE TABLE t5 (C1 CHAR(1), C2 CHAR(1), C3 INT PRIMARY KEY) ENGINE = $type ;
 
147
INSERT INTO t5 VALUES ('A','B',1), ('X','Y',2), ('X','X',3);
 
148
INSERT INTO t5 VALUES ('A','C',4), ('X','Z',5), ('A','A',6);
 
149
 
 
150
UPDATE t5,t2,t3 SET t5.C2='Q', t2.c12='R', t3.C3 ='S' WHERE t5.C1 = t2.c12 AND t5.C1 = t3.C1;
 
151
SELECT * FROM t5,t2,t3 WHERE t5.C2='Q' AND t2.c12='R' AND t3.C3 ='S' ORDER BY t5.C3,t2.c1,t3.pk1,t3.pk2;
 
152
sync_slave_with_master;
 
153
SELECT * FROM t5,t2,t3 WHERE t5.C2='Q' AND t2.c12='R' AND t3.C3 ='S' ORDER BY t5.C3,t2.c1,t3.pk1,t3.pk2;
 
154
 
 
155
#
 
156
# Testing special column types
 
157
#
 
158
 
 
159
connection master;
 
160
eval CREATE TABLE t4 (C1 CHAR(1) PRIMARY KEY, B1 BIT(1), B2 BIT(1) NOT NULL DEFAULT 0, C2 CHAR(1) NOT NULL DEFAULT 'A') ENGINE = $type ;
 
161
 
 
162
INSERT INTO t4 SET C1 = 1;
 
163
SELECT C1,HEX(B1),HEX(B2) FROM t4 ORDER BY C1;
 
164
sync_slave_with_master;
 
165
SELECT C1,HEX(B1),HEX(B2) FROM t4 ORDER BY C1;
 
166
 
 
167
#
 
168
# Testing conflicting operations
 
169
#
 
170
connection master;
 
171
eval CREATE TABLE t7 (C1 INT PRIMARY KEY, C2 INT) ENGINE = $type ;
 
172
sync_slave_with_master;
 
173
--echo --- on slave: original values ---
 
174
INSERT INTO t7 VALUES (1,3), (2,6), (3,9);
 
175
SELECT * FROM t7 ORDER BY C1;
 
176
 
 
177
# since bug#31552/31609 idempotency is not default any longer. In order
 
178
# the preceeding test INSERT INTO t7 to pass the mode is switched
 
179
# temprorarily
 
180
set @@global.slave_exec_mode= 'IDEMPOTENT';
 
181
 
 
182
connection master;
 
183
--echo --- on master: new values inserted ---
 
184
INSERT INTO t7 VALUES (1,2), (2,4), (3,6);
 
185
SELECT * FROM t7 ORDER BY C1;
 
186
sync_slave_with_master;
 
187
 
 
188
set @@global.slave_exec_mode= default;
 
189
--echo --- on slave: old values should be overwritten by replicated values ---
 
190
SELECT * FROM t7 ORDER BY C1;
 
191
 
 
192
#
 
193
# A more complicated test where the table has several keys and we are
 
194
# causing a conflict for a key that is not "last".
 
195
#
 
196
connection master;
 
197
--echo --- on master ---
 
198
eval CREATE TABLE t8 (a INT PRIMARY KEY, b INT UNIQUE, c INT UNIQUE) ENGINE = $type ;
 
199
 
 
200
# First we make sure that the constraints are correctly set.
 
201
INSERT INTO t8 VALUES (99,99,99);
 
202
--error ER_DUP_ENTRY
 
203
INSERT INTO t8 VALUES (99,22,33);
 
204
--error ER_DUP_ENTRY
 
205
INSERT INTO t8 VALUES (11,99,33);
 
206
--error ER_DUP_ENTRY
 
207
INSERT INTO t8 VALUES (11,22,99);
 
208
SELECT * FROM t8 ORDER BY a;
 
209
 
 
210
sync_slave_with_master;
 
211
--echo --- on slave ---
 
212
SELECT * FROM t8 ORDER BY a;
 
213
INSERT INTO t8 VALUES (1,2,3), (2,4,6), (3,6,9);
 
214
SELECT * FROM t8 ORDER BY a;
 
215
 
 
216
# since bug#31552/31609 idempotency is not default any longer. In order
 
217
# the preceeding test INSERT INTO t8 to pass the mode is switched
 
218
# temprorarily
 
219
set @@global.slave_exec_mode= 'IDEMPOTENT';
 
220
 
 
221
connection master;
 
222
--echo --- on master ---
 
223
# We insert a row that will cause conflict on the primary key but not
 
224
# on the other keys.
 
225
INSERT INTO t8 VALUES (2,4,8);
 
226
sync_slave_with_master;
 
227
set @@global.slave_exec_mode= default;
 
228
 
 
229
--echo --- on slave ---
 
230
SELECT * FROM t8 ORDER BY a;
 
231
 
 
232
# BUG#31552: Replication breaks when deleting rows from out-of-sync
 
233
#            table without PK
 
234
 
 
235
--echo **** Test for BUG#31552 ****
 
236
 
 
237
--echo **** On Master ****
 
238
# Clean up t1 so that we can use it.
 
239
connection master;
 
240
DELETE FROM t1;
 
241
sync_slave_with_master;
 
242
 
 
243
# Just to get a clean binary log
 
244
source include/reset_master_and_slave.inc;
 
245
 
 
246
--echo **** On Master ****
 
247
connection master;
 
248
INSERT INTO t1 VALUES ('K','K'), ('L','L'), ('M','M');
 
249
--echo **** On Master ****
 
250
sync_slave_with_master;
 
251
# since bug#31552/31609 idempotency is not default any longer. In order
 
252
# the following test DELETE FROM t1 to pass the mode is switched
 
253
# temprorarily
 
254
set @@global.slave_exec_mode= 'IDEMPOTENT';
 
255
DELETE FROM t1 WHERE C1 = 'L';
 
256
 
 
257
connection master;
 
258
DELETE FROM t1;
 
259
query_vertical SELECT COUNT(*) FROM t1 ORDER BY c1,c2;
 
260
sync_slave_with_master;
 
261
set @@global.slave_exec_mode= default;
 
262
let $last_error = query_get_value("SHOW SLAVE STATUS", Last_SQL_Errno, 1);
 
263
disable_query_log;
 
264
eval SELECT "$last_error" AS Last_SQL_Error;
 
265
enable_query_log;
 
266
query_vertical SELECT COUNT(*) FROM t1 ORDER BY c1,c2;
 
267
 
 
268
#
 
269
# cleanup
 
270
#
 
271
 
 
272
connection master;
 
273
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8;
 
274
sync_slave_with_master;