From 64c8fa58a8fe57fea8d43c8608c0e550e172305b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 9 Sep 2020 12:04:42 +0300 Subject: [PATCH] MDEV-23685 SIGSEGV on ADD FOREIGN KEY after failed ADD KEY dict_foreign_qualify_index(): Reject corrupted or garbage indexes. For index stubs that are created on virtual columns, no dict_field_t::col would be assign. Instead, the entire table definition would be reloaded on a successful operation. --- mysql-test/suite/innodb/r/foreign_key.result | 11 +++++++++++ mysql-test/suite/innodb/t/foreign_key.test | 13 +++++++++++++ storage/innobase/dict/dict0dict.cc | 6 +++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index fb4175c0327..769c1465f60 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -740,4 +740,15 @@ t2 CREATE TABLE `t2` ( CREATE TABLE t2 (f1 INT NOT NULL)ENGINE=InnoDB; ERROR 42S01: Table 't2' already exists DROP TABLE t2, t1; +# +# MDEV-23685 SIGSEGV on ADD FOREIGN KEY after failed attempt +# to create unique key on virtual column +# +CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b INT AS (a)) ENGINE=InnODB; +INSERT INTO t1 (pk,a) VALUES (1,10),(2,10); +ALTER TABLE t1 ADD UNIQUE INDEX ind9 (b), LOCK=SHARED; +ERROR 23000: Duplicate entry '10' for key 'ind9' +SET FOREIGN_KEY_CHECKS= 0; +ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (pk); +DROP TABLE t1; # End of 10.2 tests diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index e0d83338dc2..9b9c639f86b 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -720,6 +720,19 @@ SHOW CREATE TABLE t2; CREATE TABLE t2 (f1 INT NOT NULL)ENGINE=InnoDB; DROP TABLE t2, t1; +--echo # +--echo # MDEV-23685 SIGSEGV on ADD FOREIGN KEY after failed attempt +--echo # to create unique key on virtual column +--echo # +CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b INT AS (a)) ENGINE=InnODB; + +INSERT INTO t1 (pk,a) VALUES (1,10),(2,10); +--error ER_DUP_ENTRY +ALTER TABLE t1 ADD UNIQUE INDEX ind9 (b), LOCK=SHARED; +SET FOREIGN_KEY_CHECKS= 0; +ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (pk); +DROP TABLE t1; + --echo # End of 10.2 tests --source include/wait_until_count_sessions.inc diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 84478d7528b..ba0cb9e4d4e 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -6609,7 +6609,11 @@ dict_foreign_qualify_index( return(false); } - if (index->type & (DICT_SPATIAL | DICT_FTS)) { + if (index->type & (DICT_SPATIAL | DICT_FTS | DICT_CORRUPT)) { + return false; + } + + if (index->online_status >= ONLINE_INDEX_ABORTED) { return false; }