MDEV-32638 MariaDB crashes with foreign_key_checks=0 when changing a column...

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
5f09b53b (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.
parent f9d2fd1f
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment