MDEV-32638 MariaDB crashes with foreign_key_checks=0 when changing a column and adding a foreign key at the same time
Problem: ======= - InnoDB fails to find the foreign key index for the newly added foreign key relation. This is caused by commit 5f09b53bdb4e973e7c7ec2c53a24c98321223f98 (MDEV-31086). FIX: === In check_col_is_in_fk_indexes(), while iterating through the newly added foreign key relationship, InnoDB should consider that foreign key relation may not have foreign index when foreign key check is disabled.
This commit is contained in:
parent
f9d2fd1f3f
commit
b4de67da45
@ -118,4 +118,17 @@ ALTER TABLE t2 DROP INDEX idx;
|
||||
ALTER TABLE t2 MODIFY f2 VARCHAR(1023);
|
||||
SET SESSION FOREIGN_KEY_CHECKS = ON;
|
||||
DROP TABLE t2, t1;
|
||||
#
|
||||
# MDEV-32638 MariaDB crashes with foreign_key_checks=0
|
||||
# when changing a column and adding a foreign
|
||||
# key at the same time
|
||||
#
|
||||
CREATE TABLE t1(f1 VARCHAR(2) NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
|
||||
CREATE TABLE t2(f1 INT NOT NULL PRIMARY KEY,
|
||||
f2 VARCHAR(10) NOT NULL DEFAULT '')ENGINE=InnoDB;
|
||||
SET SESSION FOREIGN_KEY_CHECKS = OFF;
|
||||
ALTER TABLE t2 CHANGE COLUMN f2 f3 VARCHAR(20) NOT NULL,
|
||||
ADD CONSTRAINT t2_fk FOREIGN KEY(f3) REFERENCES t1(f1);
|
||||
DROP TABLE t2, t1;
|
||||
SET SESSION FOREIGN_KEY_CHECKS = ON;
|
||||
# End of 10.4 tests
|
||||
|
@ -153,4 +153,18 @@ ALTER TABLE t2 DROP INDEX idx;
|
||||
ALTER TABLE t2 MODIFY f2 VARCHAR(1023);
|
||||
SET SESSION FOREIGN_KEY_CHECKS = ON;
|
||||
DROP TABLE t2, t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-32638 MariaDB crashes with foreign_key_checks=0
|
||||
--echo # when changing a column and adding a foreign
|
||||
--echo # key at the same time
|
||||
--echo #
|
||||
CREATE TABLE t1(f1 VARCHAR(2) NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
|
||||
CREATE TABLE t2(f1 INT NOT NULL PRIMARY KEY,
|
||||
f2 VARCHAR(10) NOT NULL DEFAULT '')ENGINE=InnoDB;
|
||||
SET SESSION FOREIGN_KEY_CHECKS = OFF;
|
||||
ALTER TABLE t2 CHANGE COLUMN f2 f3 VARCHAR(20) NOT NULL,
|
||||
ADD CONSTRAINT t2_fk FOREIGN KEY(f3) REFERENCES t1(f1);
|
||||
DROP TABLE t2, t1;
|
||||
SET SESSION FOREIGN_KEY_CHECKS = ON;
|
||||
--echo # End of 10.4 tests
|
||||
|
@ -7695,6 +7695,7 @@ bool check_col_is_in_fk_indexes(
|
||||
|
||||
for (const auto &a : add_fk)
|
||||
{
|
||||
if (!a->foreign_index) continue;
|
||||
for (ulint i= 0; i < a->n_fields; i++)
|
||||
{
|
||||
if (a->foreign_index->fields[i].col == col)
|
||||
|
Loading…
x
Reference in New Issue
Block a user