MDEV-32060 Server aborts when table doesn't have referenced index
- Server aborts when table doesn't have referenced index. This is caused by 5f09b53bdb4e973e7c7ec2c53a24c98321223f98 (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.
This commit is contained in:
parent
1fde785315
commit
d1fca0baab
@ -81,4 +81,17 @@ DROP TABLE t2, t1;
|
||||
CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB;
|
||||
ALTER TABLE t MODIFY a VARCHAR(50), DROP b;
|
||||
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
|
||||
|
@ -111,4 +111,19 @@ DROP TABLE t2, t1;
|
||||
CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB;
|
||||
ALTER TABLE t MODIFY a VARCHAR(50), DROP b;
|
||||
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
|
||||
|
@ -7712,6 +7712,8 @@ next_item:
|
||||
{
|
||||
for (ulint i= 0; i < f->n_fields; i++)
|
||||
{
|
||||
if (!f->referenced_index)
|
||||
continue;
|
||||
if (f->referenced_index->fields[i].col == col)
|
||||
{
|
||||
my_error(ER_FK_COLUMN_CANNOT_CHANGE_CHILD, MYF(0),
|
||||
|
Loading…
x
Reference in New Issue
Block a user