-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_schemas.sql
325 lines (261 loc) · 8.86 KB
/
test_schemas.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
drop user 'usertestA'@'localhost';
drop user 'usertestB'@'localhost';
drop schema schema_A;
drop schema schema_B;
create schema schema_A;
create schema schema_B;
create user 'usertestA'@'localhost' identified by 'password';
grant select on schema_A.* to 'usertestA'@'localhost';
create user 'usertestB'@'localhost' identified by 'password';
grant select on schema_B.* to 'usertestB'@'localhost';
#######
# Table missing in either schema
create table schema_A.onlyInA(
uid INT,
PRIMARY KEY ( uid )
);
create table schema_B.onlyInB(
uid INT,
PRIMARY KEY ( uid )
);
#######
# Table with no PK
create table schema_A.nopk1(
uid INT
);
create table schema_B.nopk1(
uid INT
);
#######
# Table with no PK
create table schema_A.nopk2(
uid INT,
PRIMARY KEY ( uid )
);
create table schema_B.nopk2(
uid INT
);
#######
# Table with no PK
create table schema_A.nopk3(
uid INT
);
create table schema_B.nopk3(
uid INT,
PRIMARY KEY ( uid )
);
#######
# Tables with different PKs
create table schema_A.pkdiff1(
uid INT,
sometext VARCHAR(100),
PRIMARY KEY ( uid )
);
create table schema_B.pkdiff1(
uid INT,
sometext VARCHAR(100),
PRIMARY KEY ( sometext )
);
#######
# Tables with different PKs, but first column is same, different number of pk columns
create table schema_A.pkdiff2(
uid INT,
sometext VARCHAR(100),
PRIMARY KEY ( uid )
);
create table schema_B.pkdiff2(
uid INT,
sometext VARCHAR(100),
PRIMARY KEY ( uid, sometext )
);
#######
# Tables with different PKs, but first column is same, same number of pk columns
create table schema_A.pkdiff3(
uid INT,
sometext1 VARCHAR(100),
sometext2 VARCHAR(100),
PRIMARY KEY ( uid, sometext1 )
);
create table schema_B.pkdiff3(
uid INT,
sometext1 VARCHAR(100),
sometext2 VARCHAR(100),
PRIMARY KEY ( uid, sometext2 )
);
#######
# Tables with different PKs, pk column order is different
create table schema_A.pkdiff4(
uid INT,
sometext1 VARCHAR(100),
sometext2 VARCHAR(100),
PRIMARY KEY ( uid, sometext1 )
);
create table schema_B.pkdiff4(
uid INT,
sometext1 VARCHAR(100),
sometext2 VARCHAR(100),
PRIMARY KEY ( sometext1, uid )
);
#######
# Simple table
create table schema_A.tab1(
uid INT,
sometext VARCHAR(100),
PRIMARY KEY ( uid )
);
create table schema_B.tab1(
uid INT,
sometext VARCHAR(99),
PRIMARY KEY ( uid )
);
#schema_a uid 2 missing
#schema_b uid 5 missing
#schema_a/b uid 3 sometext different
#schema_a/b uid 7 sometext different with a NULL
insert into schema_a.tab1 (uid,sometext) values (1, 'a');
insert into schema_a.tab1 (uid,sometext) values (3, 'c');
insert into schema_a.tab1 (uid,sometext) values (4, NULL);
insert into schema_a.tab1 (uid,sometext) values (5, 'e');
insert into schema_a.tab1 (uid,sometext) values (6, 'f');
insert into schema_a.tab1 (uid,sometext) values (7, 'g');
insert into schema_b.tab1 (uid,sometext) values (1, 'a');
insert into schema_b.tab1 (uid,sometext) values (2, 'b');
insert into schema_b.tab1 (uid,sometext) values (3, 'cc');
insert into schema_b.tab1 (uid,sometext) values (4, NULL);
insert into schema_b.tab1 (uid,sometext) values (6, 'f');
insert into schema_b.tab1 (uid,sometext) values (7, NULL);
#######
# Table with only PK
create table schema_A.tab2(
uid INT,
PRIMARY KEY ( uid )
);
create table schema_B.tab2(
uid INT,
PRIMARY KEY ( uid )
);
#schema_a uid 2 missing
#schema_b uid 5 missing
insert into schema_a.tab2 (uid) values (1);
insert into schema_a.tab2 (uid) values (3);
insert into schema_a.tab2 (uid) values (4);
insert into schema_a.tab2 (uid) values (5);
insert into schema_a.tab2 (uid) values (6);
insert into schema_a.tab2 (uid) values (7);
insert into schema_b.tab2 (uid) values (1);
insert into schema_b.tab2 (uid) values (2);
insert into schema_b.tab2 (uid) values (3);
insert into schema_b.tab2 (uid) values (4);
insert into schema_b.tab2 (uid) values (6);
insert into schema_b.tab2 (uid) values (7);
#######
# Simple table with columns created in different order, inserted in different order of PK
create table schema_A.tab3(
uid INT,
sometext1 VARCHAR(100),
sometext2 VARCHAR(100),
PRIMARY KEY ( uid, sometext2 )
);
create table schema_B.tab3(
sometext2 VARCHAR(100),
sometext1 VARCHAR(100),
uid INT,
PRIMARY KEY ( uid, sometext2 )
);
#schema_a uid 4,d3 missing
#schema_a uid 6,d2 missing
#schema_b uid 4,d2 missing
#schema_a/b uid 3,c2 sometext1 different
#schema_a/b uid 5,d2 sometext1 different with a NULL
insert into schema_a.tab3 (uid,sometext1,sometext2) values (1, 'a1', 'a2');
insert into schema_a.tab3 (uid,sometext1,sometext2) values (2, 'b1', 'b2');
insert into schema_a.tab3 (uid,sometext1,sometext2) values (3, 'c1', 'c2');
insert into schema_a.tab3 (uid,sometext1,sometext2) values (4, 'd1', 'd2');
insert into schema_a.tab3 (uid,sometext1,sometext2) values (5, null, 'd2');
insert into schema_b.tab3 (uid,sometext1,sometext2) values (2, 'b1', 'b2');
insert into schema_b.tab3 (uid,sometext1,sometext2) values (1, 'a1', 'a2');
insert into schema_b.tab3 (uid,sometext1,sometext2) values (3, 'c0', 'c2');
insert into schema_b.tab3 (uid,sometext1,sometext2) values (4, 'd1', 'd3');
insert into schema_b.tab3 (uid,sometext1,sometext2) values (5, 'e1', 'd2');
insert into schema_b.tab3 (uid,sometext1,sometext2) values (6, 'e1', 'e2');
#######
# Simple table with columns created in different order, inserted in different order of PK
create table schema_A.tab4(
uid INT,
sometext1 VARCHAR(100),
sometext2 VARCHAR(100),
PRIMARY KEY ( uid )
);
create table schema_B.tab4(
uid INT,
sometext1 VARCHAR(100),
sometext3 VARCHAR(100),
PRIMARY KEY ( uid )
);
#######
# Simple table with columns created in different order, inserted in different order of PK
create table schema_A.tab5(
uid INT,
sometext1 VARCHAR(100),
sometext2 VARCHAR(100),
PRIMARY KEY ( uid, sometext1 )
);
create table schema_B.tab5(
sometext2 VARCHAR(100),
sometext1 VARCHAR(100),
uid INT,
PRIMARY KEY ( uid, sometext1 )
);
insert into schema_a.tab5 (uid,sometext1,sometext2) values (1, 'a1', 'a2');
insert into schema_a.tab5 (uid,sometext1,sometext2) values (2, 'b1', 'b2');
insert into schema_b.tab5 (uid,sometext1,sometext2) values (2, 'b1', 'b2');
insert into schema_b.tab5 (uid,sometext1,sometext2) values (1, 'a1', 'a2');
#######
# Big Table with 1,000,000 rows
create table schema_A.bigtable(
uid INT,
rndint INT,
PRIMARY KEY ( uid )
);
INSERT IGNORE INTO schema_A.bigtable ( uid, rndint )
SELECT 2 * round(rand() * 1073741823), 2 * round(rand() * 1073741823)
FROM
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t1,
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t2,
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t3,
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t4,
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t5,
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t6;
create table schema_B.bigtable(
uid INT,
rndint INT,
PRIMARY KEY ( uid )
);
INSERT IGNORE INTO schema_B.bigtable ( uid, rndint ) select sql_no_cache uid, rndint from schema_A.bigtable;
INSERT INTO schema_A.bigtable ( uid, rndint ) VALUES ( 500000001, 1234);
INSERT INTO schema_B.bigtable ( uid, rndint ) VALUES ( 500000001, 4567);
INSERT INTO schema_A.bigtable ( uid, rndint ) VALUES ( 700000001, 1234);
INSERT INTO schema_B.bigtable ( uid, rndint ) VALUES ( 300000001, 4567);
#######
# Big diff Table with 1,000 rows
create table schema_A.bigdiff(
uid INT,
rndint INT,
PRIMARY KEY ( uid )
);
INSERT IGNORE INTO schema_A.bigdiff ( uid, rndint )
SELECT 2 * round(rand() * 1073741823), 2 * round(rand() * 1073741823)
FROM
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t1,
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t2,
(select 0 as i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) as t3;
create table schema_B.bigdiff(
uid INT,
rndint INT,
PRIMARY KEY ( uid )
);
#######
# View to make sure it has no impact
create view schema_a.myview1 as select * from schema_a.tab3;
create view schema_b.myview2 as select * from schema_b.tab3;
commit;