Skip to content

Commit 923ecbd

Browse files
MDEV-23387 dict_load_foreign() fails to load the table during alter
Problem: ======= InnoDB allows virtual index to be referenced index in foreign key relations. While dropping the virtual column, Inplace alter does allow the table to be closed and open it using table name to update dict_table_t::v_cols. While loading the table, it doesn't allow any error to be ignored. InnoDB can't find the referenced virtual index and fails to load the table during Inplace alter. Solution: ========= During inplace alter, ignore the foreign key error while loading the table. Reviewed-by: Marko Mäkelä
1 parent bba2254 commit 923ecbd

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

mysql-test/suite/gcol/r/innodb_virtual_fk.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,24 @@ ID ParentID Value Flag
769769
INSERT INTO parent (ID) VALUES (100);
770770
UPDATE child SET ParentID=100 WHERE ID=123123;
771771
DROP TABLE child, parent;
772+
#
773+
# MDEV-23387 dict_load_foreign() fails to load the table during alter
774+
#
775+
SET FOREIGN_KEY_CHECKS=0;
776+
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
777+
f3 INT AS (f1) VIRTUAL,
778+
INDEX(f1), INDEX(f2))ENGINE=InnoDB;
779+
ALTER TABLE t1 ADD CONSTRAINT r FOREIGN KEY(f2) REFERENCES t1(f1), LOCK=NONE;
780+
SHOW CREATE TABLE t1;
781+
Table Create Table
782+
t1 CREATE TABLE `t1` (
783+
`f1` int(11) NOT NULL,
784+
`f2` int(11) NOT NULL,
785+
`f3` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
786+
KEY `f1` (`f1`),
787+
KEY `f2` (`f2`),
788+
CONSTRAINT `r` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
789+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
790+
ALTER TABLE t1 DROP INDEX f1;
791+
ALTER TABLE t1 DROP f3;
792+
DROP TABLE t1;

mysql-test/suite/gcol/t/innodb_virtual_fk.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,15 @@ UPDATE child SET ParentID=100 WHERE ID=123123;
637637

638638
# Cleanup
639639
DROP TABLE child, parent;
640+
--echo #
641+
--echo # MDEV-23387 dict_load_foreign() fails to load the table during alter
642+
--echo #
643+
SET FOREIGN_KEY_CHECKS=0;
644+
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
645+
f3 INT AS (f1) VIRTUAL,
646+
INDEX(f1), INDEX(f2))ENGINE=InnoDB;
647+
ALTER TABLE t1 ADD CONSTRAINT r FOREIGN KEY(f2) REFERENCES t1(f1), LOCK=NONE;
648+
SHOW CREATE TABLE t1;
649+
ALTER TABLE t1 DROP INDEX f1;
650+
ALTER TABLE t1 DROP f3;
651+
DROP TABLE t1;

storage/innobase/handler/handler0alter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8717,7 +8717,7 @@ ha_innobase::commit_inplace_alter_table(
87178717
dict_table_close(m_prebuilt->table, true, false);
87188718
dict_table_remove_from_cache(m_prebuilt->table);
87198719
m_prebuilt->table = dict_table_open_on_name(
8720-
tb_name, TRUE, TRUE, DICT_ERR_IGNORE_NONE);
8720+
tb_name, TRUE, TRUE, DICT_ERR_IGNORE_FK_NOKEY);
87218721

87228722
/* Drop outdated table stats. */
87238723
charerrstr[1024];

0 commit comments

Comments
 (0)