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
|
--source include/have_innodb.inc
--source include/not_embedded.inc
--echo #
--echo # Bug #18806829 OPENING INNODB TABLES WITH MANY FOREIGN KEY
--echo # REFERENCES IS SLOW/CRASHES SEMAPHORE
--echo #
create table t1 (f1 int primary key) engine=innodb;
insert into t1 values (5);
insert into t1 values (2882);
insert into t1 values (10);
let $fk_tables = 120;
--disable_query_log
let $i = $fk_tables;
while ($i)
{
eval create table fk_$i (f1 int primary key,
constraint pc$i foreign key (f1) references t1(f1)
on delete cascade on update cascade) engine=innodb;
eval insert into fk_$i values (5);
eval insert into fk_$i values (2882);
eval insert into fk_$i values (10);
dec $i;
}
--enable_query_log
--source include/restart_mysqld.inc
update t1 set f1 = 28 where f1 = 2882;
select * from fk_120;
select * from fk_1;
select * from fk_50;
--disable_query_log
let $i = $fk_tables;
while ($i)
{
eval drop table fk_$i;
dec $i;
}
--enable_query_log
drop table t1;
--echo #
--echo # Check if restrict is working fine.
--echo #
create table t1 (f1 int primary key) engine=innodb;
let $fk_tables = 30;
--disable_query_log
let $i = $fk_tables;
while ($i)
{
eval create table fk_$i (f1 int primary key,
constraint pc$i foreign key (f1) references t1(f1)
on delete restrict on update restrict) engine=innodb;
eval insert into t1 values ($i);
eval insert into fk_$i values ($i);
dec $i;
}
--enable_query_log
--source include/restart_mysqld.inc
--error ER_ROW_IS_REFERENCED_2
delete from t1 where f1 = 29;
select * from fk_29;
--disable_query_log
let $i = $fk_tables;
while ($i)
{
eval drop table fk_$i;
dec $i;
}
--enable_query_log
drop table t1;
#
# MDEV-7672: Crash creating an InnoDB table with foreign keys
#
CREATE TABLE t1 (
id int(11) NOT NULL AUTO_INCREMENT,
f1 int(11) DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT fk1 FOREIGN KEY (f1) REFERENCES t1 (id) ON DELETE CASCADE
) ENGINE=InnoDB;
--error 1005
CREATE TABLE t2 (
id int(11) NOT NULL AUTO_INCREMENT,
f2 int(11) NOT NULL,
f3 int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT fk2 FOREIGN KEY (f2) REFERENCES t1 (`id`) ON DELETE CASCADE,
CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE
) ENGINE=InnoDB;
show warnings;
CREATE TABLE t2 (
id int(11) NOT NULL AUTO_INCREMENT,
f2 int(11) NOT NULL,
f3 int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT fk2 FOREIGN KEY (f2) REFERENCES t1 (`id`) ON DELETE CASCADE
) ENGINE=InnoDB;
--replace_regex /'test\.#sql-[0-9_a-f-]*'/'#sql-temporary'/
--error 1005
ALTER TABLE t2 ADD CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE;
--replace_regex /'test\.#sql-[0-9_a-f-]*'/'#sql-temporary'/
show warnings;
drop table t2;
drop table t1;
|