summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thiru@mariadb.com>2020-03-25 17:10:01 +0530
committerThirunarayanan Balathandayuthapani <thiru@mariadb.com>2020-03-25 17:10:36 +0530
commit1f7be881414291d91a4cb134b75ed029f90f707d (patch)
tree2f9dda0405d3857bb1b3294fbe8ca82f4ebfff5e
parent64dd39694810c093c64c23c0f4e8de02afa921f7 (diff)
downloadmariadb-git-1f7be881414291d91a4cb134b75ed029f90f707d.tar.gz
MDEV-19092 Server crash when renaming the column when
FOREIGN_KEY_CHECKS is disabled - dict_foreign_find_index() can return NULL if InnoDB already dropped the foreign index when FOREIGN_KEY_CHECKS is disabled.
-rw-r--r--mysql-test/suite/innodb/r/foreign_key.result7
-rw-r--r--mysql-test/suite/innodb/t/foreign_key.test11
-rw-r--r--storage/innobase/dict/dict0mem.cc7
-rw-r--r--storage/xtradb/dict/dict0mem.cc7
4 files changed, 26 insertions, 6 deletions
diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result
index e56e5308909..df89766e94b 100644
--- a/mysql-test/suite/innodb/r/foreign_key.result
+++ b/mysql-test/suite/innodb/r/foreign_key.result
@@ -113,3 +113,10 @@ CREATE TABLE t2 (f INT, KEY(f)) ENGINE=InnoDB;
ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t2 (f);
ALTER IGNORE TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f1);
DROP TABLE t1, t2;
+CREATE TABLE t1 (a INT, b INT, KEY idx(a)) ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS= OFF;
+ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES tx(x);
+ALTER TABLE t1 DROP KEY idx;
+ALTER TABLE t1 CHANGE a c INT;
+DROP TABLE t1;
+SET FOREIGN_KEY_CHECKS=1;
diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test
index 08fe44911b5..ef49a79e7ed 100644
--- a/mysql-test/suite/innodb/t/foreign_key.test
+++ b/mysql-test/suite/innodb/t/foreign_key.test
@@ -134,3 +134,14 @@ CREATE TABLE t2 (f INT, KEY(f)) ENGINE=InnoDB;
ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t2 (f);
ALTER IGNORE TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f1);
DROP TABLE t1, t2;
+
+# MDEV-19092 Server crash when renaming the column when
+# FOREIGN_KEY_CHECKS is disabled
+CREATE TABLE t1 (a INT, b INT, KEY idx(a)) ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS= OFF;
+ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES tx(x);
+ALTER TABLE t1 DROP KEY idx;
+ALTER TABLE t1 CHANGE a c INT;
+# Cleanup
+DROP TABLE t1;
+SET FOREIGN_KEY_CHECKS=1;
diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc
index c5f845d14b1..bc955fb13b9 100644
--- a/storage/innobase/dict/dict0mem.cc
+++ b/storage/innobase/dict/dict0mem.cc
@@ -2,7 +2,7 @@
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
-Copyright (c) 2013, 2019, MariaDB Corporation.
+Copyright (c) 2013, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -420,9 +420,10 @@ dict_mem_table_col_rename_low(
foreign->foreign_col_names,
foreign->n_fields, NULL, true, false,
NULL, NULL, NULL);
- /* There must be an equivalent index in this case. */
- ut_ad(new_index != NULL);
+ /* New index can be null if InnoDB already dropped
+ the foreign index when FOREIGN_KEY_CHECKS is
+ disabled */
foreign->foreign_index = new_index;
} else {
diff --git a/storage/xtradb/dict/dict0mem.cc b/storage/xtradb/dict/dict0mem.cc
index f4bbc5c8f06..51ca6de8cd2 100644
--- a/storage/xtradb/dict/dict0mem.cc
+++ b/storage/xtradb/dict/dict0mem.cc
@@ -2,7 +2,7 @@
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
-Copyright (c) 2013, 2019, MariaDB Corporation.
+Copyright (c) 2013, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -421,9 +421,10 @@ dict_mem_table_col_rename_low(
foreign->foreign_col_names,
foreign->n_fields, NULL, true, false,
NULL, NULL, NULL);
- /* There must be an equivalent index in this case. */
- ut_ad(new_index != NULL);
+ /* New index can be null if XtraDB already dropped
+ the foreign index when FOREIGN_KEY_CHECKS is
+ disabled */
foreign->foreign_index = new_index;
} else {