summaryrefslogtreecommitdiff
path: root/mysql-test/suite/pbxt/r/pbxt_ref_int.result
blob: cd86d1224525490bf868f97538d8c415a798be6b (plain)
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
drop table if exists t1, t2;
CREATE TABLE t1
(
id INT PRIMARY KEY
) ENGINE=pbxt;
CREATE TABLE t2
(
v INT,
CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
) ENGINE=pbxt;
INSERT INTO t2 VALUES(2);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Constraint: `c1`)
set foreign_key_checks = 0;
drop table t1;
set foreign_key_checks = 1;
INSERT INTO t2 VALUES(2);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Referenced table `t1` not found)
drop table if exists parent, child, child_child;
CREATE TABLE parent (
id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=PBXT;
CREATE TABLE child (
id INT PRIMARY KEY,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=PBXT;
insert parent values(1);
insert parent values(2);
insert child values(100, 1);
insert child values(200, 1);
insert child values(300, 2);
insert child values(400, 2);
update parent set id = 3 where id = 1;
select * from parent;
id
2
3
select * from child order by id;
id	parent_id
100	NULL
200	NULL
300	2
400	2
delete from parent where id = 2;
select * from parent;
id
3
select * from child order by id;
id	parent_id
100	NULL
200	NULL
300	NULL
400	NULL
set foreign_key_checks = 0;
drop table if exists parent, child, child_child;
set foreign_key_checks = 1;
CREATE TABLE parent (
id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=PBXT;
CREATE TABLE child (
id INT PRIMARY KEY,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=PBXT;
CREATE TABLE child_child (
id INT PRIMARY KEY,
child_id INT,
INDEX (child_id),
FOREIGN KEY (child_id) REFERENCES child(id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=PBXT;
delete from parent;
delete from child;
delete from child_child;
insert parent values(1);
insert parent values(2);
insert child values(100, 1);
insert child values(200, 1);
insert child values(300, 2);
insert child values(400, 2);
insert child_child values(1000, 100);
insert child_child values(2000, 200);
insert child_child values(3000, 300);
insert child_child values(4000, 300);
insert child_child values(5000, 400);
select * from parent;
id
1
2
select * from child order by id;
id	parent_id
100	1
200	1
300	2
400	2
select * from child_child;
id	child_id
1000	100
2000	200
3000	300
4000	300
5000	400
update parent set id = 3 where id = 1;
select * from parent;
id
2
3
select * from child order by id;
id	parent_id
100	3
200	3
300	2
400	2
delete from parent where id = 2;
select * from parent;
id
3
select * from child order by id;
id	parent_id
100	3
200	3
select * from child_child;
id	child_id
1000	100
2000	200
set foreign_key_checks = 0;
drop table if exists parent, child, child_child;
set foreign_key_checks = 1;
CREATE TABLE parent (
id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=PBXT;
CREATE TABLE child (
id INT,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)
) ENGINE=PBXT;
insert parent values(2);
insert parent values(1);
insert child values(100, 1);
insert child values(200, 1);
update parent set id = 3 where id = 1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (Constraint: `FOREIGN_1`)
delete from parent where id = 1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (Constraint: `FOREIGN_1`)
select * from parent;
id
1
2
select * from child order by id;
id	parent_id
100	1
200	1
delete from child;
insert child values(100, 1);
insert child values(200, 1);
create index child_ind on child(id);
show create table child;
Table	Create Table
child	CREATE TABLE `child` (
  `id` int(11) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  KEY `par_ind` (`parent_id`),
  KEY `child_ind` (`id`),
  CONSTRAINT `FOREIGN_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)
) ENGINE=PBXT DEFAULT CHARSET=latin1
drop index child_ind on child;
show create table child;
Table	Create Table
child	CREATE TABLE `child` (
  `id` int(11) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  KEY `par_ind` (`parent_id`),
  CONSTRAINT `FOREIGN_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)
) ENGINE=PBXT DEFAULT CHARSET=latin1
alter table parent add column c1 varchar(40);
insert child values(2000, 2);
select * from parent;
id	c1
2	NULL
1	NULL
select * from child order by id;
id	parent_id
100	1
200	1
2000	2
show create table parent;
Table	Create Table
parent	CREATE TABLE `parent` (
  `id` int(11) NOT NULL,
  `c1` varchar(40) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=PBXT DEFAULT CHARSET=latin1
alter table parent drop column c1;
select * from parent;
id
1
2
show create table parent;
Table	Create Table
parent	CREATE TABLE `parent` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=PBXT DEFAULT CHARSET=latin1
alter table parent add column c1 int;
alter table parent drop column id;
insert child values(300, 1);
ERROR HY000: Cannot add foreign key constraint
alter table parent add column id int, add index (id);
select * from parent;
c1	id
NULL	NULL
NULL	NULL
insert child values(300, 1);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Constraint: `FOREIGN_1`)
update parent set id = 1 where id is null limit 1;
update parent set id = 2 where id is null limit 1;
insert child values(300, 1);
select * from parent order by id;
c1	id
NULL	1
NULL	2
select * from child order by id;
id	parent_id
100	1
200	1
300	1
2000	2
show create table parent;
Table	Create Table
parent	CREATE TABLE `parent` (
  `c1` int(11) DEFAULT NULL,
  `id` int(11) DEFAULT NULL,
  KEY `id` (`id`)
) ENGINE=PBXT DEFAULT CHARSET=latin1
show create table child;
Table	Create Table
child	CREATE TABLE `child` (
  `id` int(11) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  KEY `par_ind` (`parent_id`),
  CONSTRAINT `FOREIGN_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)
) ENGINE=PBXT DEFAULT CHARSET=latin1
alter table child add column c1 varchar(40);
insert child values(400, 1, "asd");
select * from parent order by id;
c1	id
NULL	1
NULL	2
select * from child order by id;
id	parent_id	c1
100	1	NULL
200	1	NULL
300	1	NULL
400	1	asd
2000	2	NULL
alter table child drop key par_ind, drop column parent_id, add column parent_id int, add key par_ind (parent_id);
insert child (id, parent_id, c1) values(500, 1, "asd");
drop table if exists child, parent;
CREATE TABLE parent (
id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=PBXT;
CREATE TABLE child (
id INT,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id)
REFERENCES parent(id) ON DELETE CASCADE
) ENGINE=PBXT;
show create table parent;
Table	Create Table
parent	CREATE TABLE `parent` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=PBXT DEFAULT CHARSET=latin1
show create table child;
Table	Create Table
child	CREATE TABLE `child` (
  `id` int(11) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  KEY `par_ind` (`parent_id`),
  CONSTRAINT `FOREIGN_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE
) ENGINE=PBXT DEFAULT CHARSET=latin1
insert parent values(1);
insert child values(100, 1);
insert child values(102, 2);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Constraint: `FOREIGN_1`)
set foreign_key_checks = 0;
drop table if exists parent, child;
set foreign_key_checks = 1;
CREATE TABLE parent (
id INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=PBXT;
CREATE TABLE child (
id INT,
parent_id INT,
INDEX par_ind (parent_id),
FOREIGN KEY (parent_id)
REFERENCES parent(glump) ON DELETE CASCADE
) ENGINE=PBXT;
insert parent values(1);
insert child values(100, 1);
ERROR HY000: Cannot add foreign key constraint
drop table if exists test1;
CREATE TABLE test1 (
id INT NOT NULL,
c1 varchar(30),
PRIMARY KEY (id)
) ENGINE=pbxt;
insert test1 values(1, "asd");
insert test1 values(2, "qwer");
alter table test1 drop column id, drop primary key, add column id int;
show create table test1;
Table	Create Table
test1	CREATE TABLE `test1` (
  `c1` varchar(30) DEFAULT NULL,
  `id` int(11) DEFAULT NULL
) ENGINE=PBXT DEFAULT CHARSET=latin1
select * from test1;
c1	id
asd	NULL
qwer	NULL
drop table if exists `ΤΑΒΜΙΓΑ`, t2;
create table `ΤΑΒΜΙΓΑ` (
id int primary key
) engine=pbxt;
CREATE TABLE t2
(
ΠΟΜΕ int NOT NULL,
cc varchar(20),
foreign key (ΠΟΜΕ) references `ΤΑΒΜΙΓΑ` (id),
index (ΠΟΜΕ)
) engine=pbxt;
insert `ΤΑΒΜΙΓΑ` values (1);
insert t2 values (1, "asd");
select * from `ΤΑΒΜΙΓΑ`;
id
1
set foreign_key_checks = 0;
drop table if exists test1, parent, child, child_child, `ΤΑΒΜΙΓΑ`, t2;
set foreign_key_checks = 1;
SET CHARACTER SET koi8r;
SET NAMES binary;
create table `тСст` (
id int primary key
) engine=pbxt;
CREATE TABLE `2тСст` (
`тСст` int,
foreign key (`тСст`) references `тСст`(id),
index (`тСст`)
) engine=pbxt;
select * from `тСст`;
id
select * from `2тСст`;
тСст
set foreign_key_checks = 0;
drop table if exists `тСст`, `2тСст`;
set foreign_key_checks = 1;
drop table if exists t2, t1;
set foreign_key_checks = 1;
CREATE TABLE t2 (s1 INT DEFAULT NULL, FOREIGN KEY (s1) REFERENCES t1 (s1));
ERROR HY000: Can't create table 'test.t2' (errno: 151)
set foreign_key_checks = 0;
CREATE TABLE t2 (s1 INT DEFAULT NULL, FOREIGN KEY (s1) REFERENCES t1 (s1));
set foreign_key_checks = 1;
insert into t2 values (1);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Referenced table `t1` not found)
set foreign_key_checks = 0;
insert into t2 values (1);
CREATE TABLE t1 (s1 INT PRIMARY KEY);
set foreign_key_checks = 1;
DROP TABLE t1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
set foreign_key_checks = 0;
DROP TABLE t1;
DROP TABLE t2;
set foreign_key_checks = 1;
CREATE TABLE t1 (s1 INT DEFAULT NULL, s2 INT DEFAULT NULL, s3 INT DEFAULT NULL, s4 INT DEFAULT NULL, 
INDEX (s1), INDEX (s2), INDEX (s3), INDEX (s4), 
FOREIGN KEY (s1) REFERENCES t1 (s2), 
FOREIGN KEY (s2) REFERENCES t1 (s3),
FOREIGN KEY (s3) REFERENCES t1 (s4));
DROP TABLE t1;
CREATE TABLE t1 (s1 INT DEFAULT NULL, s2 INT DEFAULT NULL, s3 INT DEFAULT NULL, s4 INT DEFAULT NULL, 
INDEX (s1), INDEX (s2), INDEX (s3), INDEX (s4), 
FOREIGN KEY (s1) REFERENCES t1 (s2), 
FOREIGN KEY (s2) REFERENCES t1 (s3),
FOREIGN KEY (s3) REFERENCES t1 (s4));
CREATE TABLE t2 (s1 INT DEFAULT NULL, FOREIGN KEY (s1) REFERENCES t1 (s1));
DROP TABLE t1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
DROP TABLE t2;
DROP TABLE t1;
CREATE TABLE t2 (s1 INT, INDEX (s1));
set foreign_key_checks = 0;
ALTER TABLE t2 ADD FOREIGN KEY (s1) REFERENCES t1 (s1);
DROP TABLE IF EXISTS t2, t1;
set foreign_key_checks = 1;