1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-05 12:42:17 +03:00
Files
mariadb/mysql-test/suite/innodb/r/innodb_bug68148.result
Marko Mäkelä 9de2e60d74 MDEV-17187 table doesn't exist in engine after ALTER of FOREIGN KEY
ha_innobase::open(): Always ignore problems with FOREIGN KEY constraints
(pass DICT_ERR_IGNORE_FK_NOKEY), no matter whether foreign_key_checks
is enabled. Instead, we must report errors when enforcing the FOREIGN KEY
constraints. As a result of ignoring these errors, the tables will be
loaded with dict_foreign_t objects whose foreign_index or referenced_index
will be NULL.

Also, pass DICT_ERR_IGNORE_FK_NOKEY instead of DICT_ERR_IGNORE_NONE
to dict_table_open_on_id_low() in many other cases. Notably, on
CREATE TABLE and ALTER TABLE, we will keep validating the FOREIGN KEY
constraints as before.

dict_table_open_on_name(): If no other flags than
DICT_ERR_IGNORE_FK_NOKEY are set, refuse access to unreadable tables.
Some encryption tests rely on this code path.

For the DML code path, we used to have the problem that when
one of the indexes was missing in dict_foreign_t, we would ignore
the FOREIGN KEY constraint altogether. The following changes
address that.

row_ins_check_foreign_constraints(): Add the parameter pk.
For the primary key, consider also foreign key constraints for which
foreign->foreign_index=NULL (no underlying index is available).

row_ins_check_foreign_constraint(): Report errors also for !check_ref.
Remove a redundant check for srv_read_only_mode.

row_ins_foreign_report_add_err(): Tolerate foreign->foreign_index=NULL.
2019-08-21 11:38:33 +03:00

36 lines
1.3 KiB
Plaintext

set global innodb_file_per_table=1;
CREATE TABLE ref_table1 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
CREATE TABLE ref_table2 (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
CREATE TABLE `main` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ref_id1` int(11) NOT NULL,
`ref_id2` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_1` (`ref_id1`,`ref_id2`),
KEY `FK_set_out_analysis_route_id` (`ref_id2`),
CONSTRAINT `FK_1` FOREIGN KEY (`ref_id1`) REFERENCES `ref_table1` (`id`) ,
CONSTRAINT `FK_2` FOREIGN KEY (`ref_id2`) REFERENCES `ref_table2` (`id`)
) ENGINE=InnoDB;
SET FOREIGN_KEY_CHECKS=0;
DROP INDEX `idx_1` ON `main`;
SHOW TABLES;
Tables_in_test
main
ref_table1
ref_table2
# restart and see if we can still access the main table
ALTER TABLE `main` ADD INDEX `idx_1` (`ref_id1`);
SHOW CREATE TABLE `main`;
Table Create Table
main CREATE TABLE `main` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ref_id1` int(11) NOT NULL,
`ref_id2` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_set_out_analysis_route_id` (`ref_id2`),
KEY `idx_1` (`ref_id1`),
CONSTRAINT `FK_1` FOREIGN KEY (`ref_id1`) REFERENCES `ref_table1` (`id`),
CONSTRAINT `FK_2` FOREIGN KEY (`ref_id2`) REFERENCES `ref_table2` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
DROP TABLE main, ref_table1, ref_table2;