~vkolesnikov/pbxt/pbxt-07-diskfull

« back to all changes in this revision

Viewing changes to pbxt/mysql-test-update/mysql-test/include/rpl_row_basic.inc

  • Committer: paul-mccullagh
  • Date: 2006-10-23 09:14:04 UTC
  • Revision ID: paul-mccullagh-918861e03d351978a9541168a96e58cc826734ee
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--source include/have_row_based.inc
 
2
--source include/have_binlog_format_row.inc
 
3
--source include/master-slave.inc
 
4
 
 
5
#
 
6
# Basic tests of row-level logging
 
7
#
 
8
 
 
9
#
 
10
# First we test tables with only an index.
 
11
#
 
12
 
 
13
eval CREATE TABLE t1 (C1 CHAR(1), C2 CHAR(1), INDEX (C1)$extra_index_t1) ENGINE = $type ;
 
14
SELECT * FROM t1;
 
15
sync_slave_with_master;
 
16
SELECT * FROM t1;
 
17
 
 
18
# Testing insert
 
19
connection master;
 
20
INSERT INTO t1 VALUES ('A','B'), ('X','Y'), ('X','X');
 
21
INSERT INTO t1 VALUES ('A','C'), ('X','Z'), ('A','A');
 
22
SELECT * FROM t1 ORDER BY C1,C2;
 
23
sync_slave_with_master;
 
24
SELECT * FROM t1 ORDER BY C1,C2;
 
25
 
 
26
# Testing delete
 
27
# Observe that are several rows having the value for the index but only one
 
28
# should be deleted.
 
29
connection master;
 
30
DELETE FROM t1 WHERE C1 = C2;
 
31
SELECT * FROM t1 ORDER BY C1,C2;
 
32
sync_slave_with_master;
 
33
SELECT * FROM t1 ORDER BY C1,C2;
 
34
 
 
35
#
 
36
# Testing update.
 
37
# Note that we have a condition on a column that is not part of the index for
 
38
# the table. The right row should be updated nevertheless.
 
39
#
 
40
connection master;
 
41
UPDATE t1 SET C2 = 'I' WHERE C1 = 'A' AND C2 = 'C';
 
42
SELECT * FROM t1 ORDER BY C1,C2;
 
43
sync_slave_with_master;
 
44
SELECT * FROM t1 ORDER BY C1,C2;
 
45
 
 
46
# Testing update with a condition that does not match any rows, but
 
47
# which has a match for the index.
 
48
connection master;
 
49
UPDATE t1 SET c2 = 'Q' WHERE c1 = 'A' AND c2 = 'N';
 
50
SELECT * FROM t1 ORDER BY c1,c2;
 
51
sync_slave_with_master;
 
52
SELECT * FROM t1 ORDER BY c1,c2;
 
53
 
 
54
#
 
55
# Testing table with primary key
 
56
#
 
57
connection master;
 
58
eval CREATE TABLE t2 (c1 INT, c12 char(1), c2 INT, PRIMARY KEY (c1)) ENGINE = $type ;
 
59
INSERT INTO t2
 
60
  VALUES (1,'A',2),  (2,'A',4),  (3,'A',9),  (4,'A',15), (5,'A',25),
 
61
         (6,'A',35), (7,'A',50), (8,'A',64), (9,'A',81);
 
62
SELECT * FROM t2 ORDER BY c1,c2;
 
63
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
64
sync_slave_with_master;
 
65
SELECT * FROM t2 ORDER BY c1,c2;
 
66
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
67
 
 
68
connection master;
 
69
UPDATE t2 SET c2 = c1*c1 WHERE c2 != c1*c1;
 
70
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
71
sync_slave_with_master;
 
72
SELECT * FROM t2 WHERE c2 = c1 * c1 ORDER BY c1,c2;
 
73
 
 
74
# Testing update with a condition that does not match any rows, but
 
75
# which has a match for the primary key.
 
76
connection master;
 
77
UPDATE t2 SET c12 = 'Q' WHERE c1 = 1 AND c2 = 999;
 
78
SELECT * FROM t2 ORDER BY c1,c2;
 
79
sync_slave_with_master;
 
80
SELECT * FROM t2 ORDER BY c1,c2;
 
81
 
 
82
connection master;
 
83
DELETE FROM t2 WHERE c1 % 4 = 0;
 
84
SELECT * FROM t2 ORDER BY c1,c2;
 
85
sync_slave_with_master;
 
86
SELECT * FROM t2 ORDER BY c1,c2;
 
87
 
 
88
connection master;
 
89
UPDATE t2 SET c12='X';
 
90
 
 
91
#
 
92
# Testing table with a multi-column primary key.
 
93
#
 
94
connection master;
 
95
eval CREATE TABLE t3 (C1 CHAR(1), C2 CHAR(1), pk1 INT, C3 CHAR(1), pk2 INT, PRIMARY KEY (pk1,pk2)) ENGINE = $type ;
 
96
 
 
97
INSERT INTO t3 VALUES ('A','B',1,'B',1), ('X','Y',2,'B',1), ('X','X',3,'B',1);
 
98
INSERT INTO t3 VALUES ('A','C',1,'B',2), ('X','Z',2,'B',2), ('A','A',3,'B',2);
 
99
SELECT * FROM t3 ORDER BY C1,C2;
 
100
sync_slave_with_master;
 
101
SELECT * FROM t3 ORDER BY C1,C2;
 
102
 
 
103
connection master;
 
104
DELETE FROM t3 WHERE C1 = C2;
 
105
SELECT * FROM t3 ORDER BY C1,C2;
 
106
sync_slave_with_master;
 
107
SELECT * FROM t3 ORDER BY C1,C2;
 
108
 
 
109
connection master;
 
110
UPDATE t3 SET C2 = 'I' WHERE C1 = 'A' AND C2 = 'C';
 
111
SELECT * FROM t3 ORDER BY C1,C2;
 
112
sync_slave_with_master;
 
113
SELECT * FROM t3 ORDER BY C1,C2;
 
114
 
 
115
#
 
116
# Testing table without index or primary key
 
117
#
 
118
connection master;
 
119
eval CREATE TABLE t6 (C1 CHAR(1), C2 CHAR(1), C3 INT$extra_index_t6) ENGINE = $type;
 
120
 
 
121
# Testing insert
 
122
INSERT INTO t6 VALUES ('A','B',1), ('X','Y',2), ('X','X',3);
 
123
INSERT INTO t6 VALUES ('A','C',4), ('X','Z',5), ('A','A',6);
 
124
SELECT * FROM t6 ORDER BY C3;
 
125
sync_slave_with_master;
 
126
SELECT * FROM t6 ORDER BY C3;
 
127
 
 
128
# Testing delete
 
129
# Observe that are several rows having the value for the index but only one
 
130
# should be deleted.
 
131
connection master;
 
132
DELETE FROM t6 WHERE C1 = C2;
 
133
SELECT * FROM t6 ORDER BY C3;
 
134
sync_slave_with_master;
 
135
SELECT * FROM t6 ORDER BY C3;
 
136
 
 
137
#
 
138
# Testing update.
 
139
# Note that we have a condition on a column that is not part of the index for
 
140
# the table. The right row should be updated nevertheless.
 
141
#
 
142
connection master;
 
143
UPDATE t6 SET C2 = 'I' WHERE C1 = 'A' AND C2 = 'C';
 
144
SELECT * FROM t6 ORDER BY C3;
 
145
sync_slave_with_master;
 
146
SELECT * FROM t6 ORDER BY C3;
 
147
 
 
148
# now mixing the 3 tables without begin/commit
 
149
connection master;
 
150
eval CREATE TABLE t5 (C1 CHAR(1), C2 CHAR(1), C3 INT PRIMARY KEY) ENGINE = $type ;
 
151
INSERT INTO t5 VALUES ('A','B',1), ('X','Y',2), ('X','X',3);
 
152
INSERT INTO t5 VALUES ('A','C',4), ('X','Z',5), ('A','A',6);
 
153
 
 
154
UPDATE t5,t2,t3 SET t5.C2='Q', t2.c12='R', t3.C3 ='S' WHERE t5.C1 = t2.c12 AND t5.C1 = t3.C1;
 
155
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;
 
156
sync_slave_with_master;
 
157
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;
 
158
 
 
159
#
 
160
# Testing special column types
 
161
#
 
162
 
 
163
connection master;
 
164
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 ;
 
165
 
 
166
INSERT INTO t4 SET C1 = 1;
 
167
SELECT C1,HEX(B1),HEX(B2) FROM t4 ORDER BY C1;
 
168
sync_slave_with_master;
 
169
SELECT C1,HEX(B1),HEX(B2) FROM t4 ORDER BY C1;
 
170
 
 
171
#
 
172
# Testing conflicting operations
 
173
#
 
174
connection master;
 
175
eval CREATE TABLE t7 (C1 INT PRIMARY KEY, C2 INT) ENGINE = $type ;
 
176
sync_slave_with_master;
 
177
--echo --- on slave: original values ---
 
178
INSERT INTO t7 VALUES (1,3), (2,6), (3,9);
 
179
SELECT * FROM t7 ORDER BY C1;
 
180
 
 
181
connection master;
 
182
--echo --- on master: new values inserted ---
 
183
INSERT INTO t7 VALUES (1,2), (2,4), (3,6);
 
184
SELECT * FROM t7 ORDER BY C1;
 
185
sync_slave_with_master;
 
186
--echo --- on slave: old values should be overwritten by replicated values ---
 
187
SELECT * FROM t7 ORDER BY C1;
 
188
 
 
189
#
 
190
# A more complicated test where the table has several keys and we are
 
191
# causing a conflict for a key that is not "last".
 
192
#
 
193
connection master;
 
194
--echo --- on master ---
 
195
eval CREATE TABLE t8 (a INT PRIMARY KEY, b INT UNIQUE, c INT UNIQUE) ENGINE = $type ;
 
196
 
 
197
# First we make sure that the constraints are correctly set.
 
198
INSERT INTO t8 VALUES (99,99,99);
 
199
--error 1062
 
200
INSERT INTO t8 VALUES (99,22,33);
 
201
--error 1062
 
202
INSERT INTO t8 VALUES (11,99,33);
 
203
--error 1062
 
204
INSERT INTO t8 VALUES (11,22,99);
 
205
SELECT * FROM t8 ORDER BY a;
 
206
 
 
207
sync_slave_with_master;
 
208
--echo --- on slave ---
 
209
SELECT * FROM t8 ORDER BY a;
 
210
INSERT INTO t8 VALUES (1,2,3), (2,4,6), (3,6,9);
 
211
SELECT * FROM t8 ORDER BY a;
 
212
 
 
213
connection master;
 
214
--echo --- on master ---
 
215
# We insert a row that will cause conflict on the primary key but not
 
216
# on the other keys.
 
217
INSERT INTO t8 VALUES (2,4,8);
 
218
sync_slave_with_master;
 
219
--echo --- on slave ---
 
220
SELECT * FROM t8 ORDER BY a;
 
221
 
 
222
#
 
223
# Test conflicting operations when changing in a table referenced by a
 
224
# foreign key.  We'll reuse the above table and just add a table that
 
225
# references it.
 
226
#
 
227
 
 
228
#
 
229
# cleanup
 
230
#
 
231
 
 
232
connection master;
 
233
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8;