Skip to content

Commit

Permalink
MDEV-25691 fixup: Correctly drop orphan foreign keys
Browse files Browse the repository at this point in the history
innodb_drop_database_fk(): Use the correct length when comparing.
Fix a debug assertion in previously unreachable code.
This error was caught by MSAN.

innodb_drop_database(): Correct the SQL for traversing SYS_FOREIGN.
The incorrect code would cause orphan FOREIGN KEY entries to be
left behind in the test innodb.alter_foreign_crash.
  • Loading branch information
dr-m committed May 19, 2021
1 parent 5d495fc commit 2714158
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1295,12 +1295,13 @@ static ibool innodb_drop_database_fk(void *node, void *report)
ut_ad(name->type.mtype == DATA_VARCHAR);

if (name->len == UNIV_SQL_NULL || name->len <= r->name.size() ||
memcmp(static_cast<const char*>(name->data), r->name.data(), name->len))
memcmp(static_cast<const char*>(name->data), r->name.data(),
r->name.size()))
return false; /* End of matches */

node= que_node_get_next(s->select_list);
const dfield_t *id= que_node_get_val(node);
ut_ad(id->type.mtype == DATA_BINARY);
ut_ad(id->type.mtype == DATA_VARCHAR);
ut_ad(!que_node_get_next(node));

if (id->len != UNIV_SQL_NULL)
Expand Down Expand Up @@ -1407,8 +1408,7 @@ static void innodb_drop_database(handlerton*, char *path)
"DECLARE FUNCTION fk_report;\n"

"DECLARE CURSOR fkf IS\n"
"SELECT ID FROM SYS_FOREIGN WHERE FOR_NAME >= :db FOR UPDATE\n"
"ORDER BY FOR_NAME;\n"
"SELECT ID FROM SYS_FOREIGN WHERE ID >= :db FOR UPDATE;\n"

"DECLARE CURSOR fkr IS\n"
"SELECT REF_NAME,ID FROM SYS_FOREIGN WHERE REF_NAME >= :db FOR UPDATE\n"
Expand All @@ -1428,7 +1428,7 @@ static void innodb_drop_database(handlerton*, char *path)
" IF (SQL % NOTFOUND) THEN EXIT; END IF;\n"
" IF SUBSTR(fk, 0, LENGTH(:db)) <> :db THEN EXIT; END IF;\n"
" DELETE FROM SYS_FOREIGN_COLS WHERE ID=fk;\n"
" DELETE FROM SYS_FOREIGN WHERE FOR_NAME=fk;\n"
" DELETE FROM SYS_FOREIGN WHERE CURRENT OF fkf;\n"
"END LOOP;\n"
"CLOSE fkf;\n"

Expand Down

0 comments on commit 2714158

Please sign in to comment.