MDEV-32060 Server aborts when table doesn't have referenced index

- Server aborts when table doesn't have referenced index.
This is caused by 5f09b53b (MDEV-31086).
While iterating the foreign key constraints, we fail to
consider that InnoDB doesn't have referenced index for
it when foreign key check is disabled.
parent 1fde7853
...@@ -81,4 +81,17 @@ DROP TABLE t2, t1; ...@@ -81,4 +81,17 @@ DROP TABLE t2, t1;
CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB; CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB;
ALTER TABLE t MODIFY a VARCHAR(50), DROP b; ALTER TABLE t MODIFY a VARCHAR(50), DROP b;
DROP TABLE t; DROP TABLE t;
#
# MDEV-32060 Server aborts when table doesn't
# have referenced index
#
SET SESSION FOREIGN_KEY_CHECKS = OFF;
CREATE TABLE t1 (a VARCHAR(16) KEY, FOREIGN KEY(a) REFERENCES t2(b)) ENGINE=InnoDB;
CREATE TABLE t2 (b VARCHAR(8)) ENGINE=InnoDB;
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
SET SESSION FOREIGN_KEY_CHECKS = ON;
ALTER TABLE t2 MODIFY b VARCHAR(16), ADD KEY(b);
ERROR 42S02: Table 'test.t2' doesn't exist
DROP TABLE t2, t1;
ERROR 42S02: Unknown table 'test.t2'
# End of 10.4 tests # End of 10.4 tests
...@@ -111,4 +111,19 @@ DROP TABLE t2, t1; ...@@ -111,4 +111,19 @@ DROP TABLE t2, t1;
CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB; CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB;
ALTER TABLE t MODIFY a VARCHAR(50), DROP b; ALTER TABLE t MODIFY a VARCHAR(50), DROP b;
DROP TABLE t; DROP TABLE t;
--echo #
--echo # MDEV-32060 Server aborts when table doesn't
--echo # have referenced index
--echo #
SET SESSION FOREIGN_KEY_CHECKS = OFF;
CREATE TABLE t1 (a VARCHAR(16) KEY, FOREIGN KEY(a) REFERENCES t2(b)) ENGINE=InnoDB;
# Following SQL is allowed in 10.6
--error ER_CANT_CREATE_TABLE
CREATE TABLE t2 (b VARCHAR(8)) ENGINE=InnoDB;
SET SESSION FOREIGN_KEY_CHECKS = ON;
--error ER_NO_SUCH_TABLE
ALTER TABLE t2 MODIFY b VARCHAR(16), ADD KEY(b);
--error ER_BAD_TABLE_ERROR
DROP TABLE t2, t1;
--echo # End of 10.4 tests --echo # End of 10.4 tests
...@@ -7712,6 +7712,8 @@ bool check_col_is_in_fk_indexes( ...@@ -7712,6 +7712,8 @@ bool check_col_is_in_fk_indexes(
{ {
for (ulint i= 0; i < f->n_fields; i++) for (ulint i= 0; i < f->n_fields; i++)
{ {
if (!f->referenced_index)
continue;
if (f->referenced_index->fields[i].col == col) if (f->referenced_index->fields[i].col == col)
{ {
my_error(ER_FK_COLUMN_CANNOT_CHANGE_CHILD, MYF(0), my_error(ER_FK_COLUMN_CANNOT_CHANGE_CHILD, MYF(0),
......
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