Commit 7ff9e583 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-25748 DROP DATABASE drops unrelated FOREIGN KEY constraints

innodb_drop_database(): Apply binary comparison.
(SYS_FOREIGN.ID unfortunately uses latin1_swedish_ci collation.)
parent 3246e729
......@@ -3,12 +3,17 @@
# COMMIT_INPLACE_ALTER_TABLE
#
call mtr.add_suppression("InnoDB: Failed to load table");
CREATE DATABASE Bug;
CREATE TABLE Bug.parent(a SERIAL) ENGINE=INNODB;
CREATE TABLE Bug.child(a SERIAL, FOREIGN KEY f(a) REFERENCES Bug.parent(a))
ENGINE=INNODB;
create database bug;
use bug;
create table parent(a serial) engine=innodb;
create table child(a serial, foreign key fk (a) references parent(a))engine=innodb;
insert into parent values(1);
insert into child values(1);
drop database Bug;
connect con1,localhost,root,,bug;
SET DEBUG_SYNC='innodb_rename_table_ready SIGNAL s1 WAIT_FOR s2 EXECUTE 2';
ALTER TABLE child ROW_FORMAT=DYNAMIC, ALGORITHM=COPY;
......
......@@ -2,6 +2,7 @@
--source include/have_debug_sync.inc
# The embedded server does not support restarting.
--source include/not_embedded.inc
--source include/have_case_sensitive_file_system.inc
--echo #
--echo # Bug #20476395 DICT_LOAD_FOREIGNS() FAILED IN
......@@ -10,6 +11,11 @@
call mtr.add_suppression("InnoDB: Failed to load table");
CREATE DATABASE Bug;
CREATE TABLE Bug.parent(a SERIAL) ENGINE=INNODB;
CREATE TABLE Bug.child(a SERIAL, FOREIGN KEY f(a) REFERENCES Bug.parent(a))
ENGINE=INNODB;
create database bug;
use bug;
......@@ -18,6 +24,7 @@ create table child(a serial, foreign key fk (a) references parent(a))engine=inno
insert into parent values(1);
insert into child values(1);
drop database Bug;
connect (con1,localhost,root,,bug);
SET DEBUG_SYNC='innodb_rename_table_ready SIGNAL s1 WAIT_FOR s2 EXECUTE 2';
......
......@@ -1424,8 +1424,9 @@ static void innodb_drop_database(handlerton*, char *path)
"WHILE 1 = 1 LOOP\n"
" FETCH fkf INTO fk;\n"
" 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"
" IF TO_BINARY(SUBSTR(fk, 0, LENGTH(:db)))<>TO_BINARY(:db)"
" THEN EXIT; END IF;\n"
" DELETE FROM SYS_FOREIGN_COLS WHERE TO_BINARY(ID)=TO_BINARY(fk);\n"
" DELETE FROM SYS_FOREIGN WHERE CURRENT OF fkf;\n"
"END LOOP;\n"
"CLOSE fkf;\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment