summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2019-04-03 10:57:45 +0200
committerSergei Golubchik <serg@mariadb.org>2019-04-24 11:15:38 +0200
commit81a8d8be76b1cc22d8567ed66cf8c6b93591112c (patch)
tree5bce62fbe10cc2e05276dc175600233e458adb1c
parentd5da8ae04d57556f517c0f03afeafe73c6cc75d1 (diff)
downloadmariadb-git-81a8d8be76b1cc22d8567ed66cf8c6b93591112c.tar.gz
MDEV-18923 Assertion `!lex_string_cmp(system_charset_info, fk_info->referenced_table, &table->s->table_name)' failed in fk_truncate_illegal_if_parent
don't assert the correctness of FK constraints, as it can be broken under `SET FOREIGN_KEY_CHECKS= OFF`
-rw-r--r--mysql-test/suite/innodb/r/innodb-truncate.result13
-rw-r--r--mysql-test/suite/innodb/t/innodb-truncate.test16
-rw-r--r--sql/sql_truncate.cc14
3 files changed, 34 insertions, 9 deletions
diff --git a/mysql-test/suite/innodb/r/innodb-truncate.result b/mysql-test/suite/innodb/r/innodb-truncate.result
index f63e9272850..e4b571cbc2f 100644
--- a/mysql-test/suite/innodb/r/innodb-truncate.result
+++ b/mysql-test/suite/innodb/r/innodb-truncate.result
@@ -66,3 +66,16 @@ a
1
2
DROP TABLE t1;
+call mtr.add_suppression('InnoDB: Error: in RENAME TABLE table `test`.`t3`');
+SET FOREIGN_KEY_CHECKS= OFF;
+CREATE TABLE t1 (f2 INT, f4 INT, KEY(f2), FOREIGN KEY (f4) REFERENCES t3 (f4)) ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS= ON;
+CREATE TABLE t2 (f2 INT, FOREIGN KEY(f2) REFERENCES t1 (f2)) ENGINE=InnoDB;
+CREATE TABLE t3 (a INT) ENGINE=InnoDB;
+ERROR HY000: Can't create table 'test.t3' (errno: 150)
+ALTER TABLE t1 RENAME TO t3;
+ERROR HY000: Error on rename of './test/t1' to './test/t3' (errno: 150)
+ALTER TABLE t1 FORCE;
+TRUNCATE TABLE t1;
+ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `test`.`t3` (`f2`))
+DROP TABLE t2, t1;
diff --git a/mysql-test/suite/innodb/t/innodb-truncate.test b/mysql-test/suite/innodb/t/innodb-truncate.test
index ae25aabd323..d7262c30543 100644
--- a/mysql-test/suite/innodb/t/innodb-truncate.test
+++ b/mysql-test/suite/innodb/t/innodb-truncate.test
@@ -62,3 +62,19 @@ INSERT INTO t1 VALUES (NULL), (NULL);
SELECT * FROM t1 ORDER BY a;
DROP TABLE t1;
+#
+# MDEV-18923 Assertion `!lex_string_cmp(system_charset_info, fk_info->referenced_table, &table->s->table_name)' failed in fk_truncate_illegal_if_parent
+#
+call mtr.add_suppression('InnoDB: Error: in RENAME TABLE table `test`.`t3`');
+SET FOREIGN_KEY_CHECKS= OFF;
+CREATE TABLE t1 (f2 INT, f4 INT, KEY(f2), FOREIGN KEY (f4) REFERENCES t3 (f4)) ENGINE=InnoDB;
+SET FOREIGN_KEY_CHECKS= ON;
+CREATE TABLE t2 (f2 INT, FOREIGN KEY(f2) REFERENCES t1 (f2)) ENGINE=InnoDB;
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t3 (a INT) ENGINE=InnoDB;
+--error ER_ERROR_ON_RENAME
+ALTER TABLE t1 RENAME TO t3;
+ALTER TABLE t1 FORCE;
+--error ER_TRUNCATE_ILLEGAL_FK
+TRUNCATE TABLE t1;
+DROP TABLE t2, t1;
diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc
index ed36ab428a2..b225d5f04df 100644
--- a/sql/sql_truncate.cc
+++ b/sql/sql_truncate.cc
@@ -150,15 +150,11 @@ fk_truncate_illegal_if_parent(THD *thd, TABLE *table)
/* Loop over the set of foreign keys for which this table is a parent. */
while ((fk_info= it++))
{
- DBUG_ASSERT(!my_strcasecmp(system_charset_info,
- fk_info->referenced_db->str,
- table->s->db.str));
-
- DBUG_ASSERT(!my_strcasecmp(system_charset_info,
- fk_info->referenced_table->str,
- table->s->table_name.str));
-
- if (my_strcasecmp(system_charset_info, fk_info->foreign_db->str,
+ if (my_strcasecmp(system_charset_info, fk_info->referenced_db->str,
+ table->s->db.str) ||
+ my_strcasecmp(system_charset_info, fk_info->referenced_table->str,
+ table->s->table_name.str) ||
+ my_strcasecmp(system_charset_info, fk_info->foreign_db->str,
table->s->db.str) ||
my_strcasecmp(system_charset_info, fk_info->foreign_table->str,
table->s->table_name.str))