Skip to content

Commit 006acf7

Browse files
author
Jan Lindström
committed
Bug #68148: drop index on a foreign key column leads to missing table
MDEV-8845: Table disappear after modifying FK Added test case.
1 parent a95711e commit 006acf7

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
set global innodb_file_per_table=1;
2+
CREATE TABLE ref_table1 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
3+
CREATE TABLE ref_table2 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
4+
CREATE TABLE `main` (
5+
`id` int(11) NOT NULL AUTO_INCREMENT,
6+
`ref_id1` int(11) NOT NULL,
7+
`ref_id2` int(11) NOT NULL,
8+
PRIMARY KEY (`id`),
9+
UNIQUE KEY `idx_1` (`ref_id1`,`ref_id2`),
10+
KEY `FK_set_out_analysis_route_id` (`ref_id2`),
11+
CONSTRAINT `FK_1` FOREIGN KEY (`ref_id1`) REFERENCES `ref_table1` (`id`) ,
12+
CONSTRAINT `FK_2` FOREIGN KEY (`ref_id2`) REFERENCES `ref_table2` (`id`)
13+
) ENGINE=InnoDB;
14+
SET FOREIGN_KEY_CHECKS=0;
15+
DROP INDEX `idx_1` ON `main`;
16+
SHOW TABLES;
17+
Tables_in_test
18+
main
19+
ref_table1
20+
ref_table2
21+
# restart and see if we can still access the main table
22+
SET FOREIGN_KEY_CHECKS=0;
23+
ALTER TABLE `main` ADD INDEX `idx_1` (`ref_id1`);
24+
SHOW CREATE TABLE `main`;
25+
Table Create Table
26+
main CREATE TABLE `main` (
27+
`id` int(11) NOT NULL AUTO_INCREMENT,
28+
`ref_id1` int(11) NOT NULL,
29+
`ref_id2` int(11) NOT NULL,
30+
PRIMARY KEY (`id`),
31+
KEY `FK_set_out_analysis_route_id` (`ref_id2`),
32+
KEY `idx_1` (`ref_id1`),
33+
CONSTRAINT `FK_1` FOREIGN KEY (`ref_id1`) REFERENCES `ref_table1` (`id`),
34+
CONSTRAINT `FK_2` FOREIGN KEY (`ref_id2`) REFERENCES `ref_table2` (`id`)
35+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
36+
DROP TABLE main, ref_table1, ref_table2;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- source include/have_innodb.inc
2+
-- source include/not_embedded.inc
3+
4+
#
5+
# Bug #68148: drop index on a foreign key column leads to missing table
6+
# MDEV-8845: Table disappear after modifying FK
7+
#
8+
9+
set global innodb_file_per_table=1;
10+
11+
CREATE TABLE ref_table1 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
12+
13+
CREATE TABLE ref_table2 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
14+
15+
CREATE TABLE `main` (
16+
`id` int(11) NOT NULL AUTO_INCREMENT,
17+
`ref_id1` int(11) NOT NULL,
18+
`ref_id2` int(11) NOT NULL,
19+
PRIMARY KEY (`id`),
20+
UNIQUE KEY `idx_1` (`ref_id1`,`ref_id2`),
21+
KEY `FK_set_out_analysis_route_id` (`ref_id2`),
22+
CONSTRAINT `FK_1` FOREIGN KEY (`ref_id1`) REFERENCES `ref_table1` (`id`) ,
23+
CONSTRAINT `FK_2` FOREIGN KEY (`ref_id2`) REFERENCES `ref_table2` (`id`)
24+
) ENGINE=InnoDB;
25+
26+
SET FOREIGN_KEY_CHECKS=0;
27+
28+
DROP INDEX `idx_1` ON `main`;
29+
SHOW TABLES;
30+
31+
--echo # restart and see if we can still access the main table
32+
--source include/restart_mysqld.inc
33+
34+
# This is required to access the table
35+
SET FOREIGN_KEY_CHECKS=0;
36+
ALTER TABLE `main` ADD INDEX `idx_1` (`ref_id1`);
37+
SHOW CREATE TABLE `main`;
38+
39+
DROP TABLE main, ref_table1, ref_table2;
40+
41+

0 commit comments

Comments
 (0)