From 1f3f4571934140fd81f54aa366cc4656544c89f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Mon, 13 Jun 2022 17:05:31 +0300 Subject: [PATCH] MDEV-28802 DROP DATABASE in InnoDB still is case-insensitive innodb_drop_database(): Use explicit TO_BINARY casts on SYS_TABLES.NAME, which for historical reasons uses the wrong collation latin1_swedish_ci instead of BINARY. --- mysql-test/suite/innodb/r/dropdb_cs.result | 16 ++++++++++++++++ mysql-test/suite/innodb/t/dropdb_cs.test | 17 +++++++++++++++++ storage/innobase/handler/ha_innodb.cc | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/innodb/r/dropdb_cs.result create mode 100644 mysql-test/suite/innodb/t/dropdb_cs.test diff --git a/mysql-test/suite/innodb/r/dropdb_cs.result b/mysql-test/suite/innodb/r/dropdb_cs.result new file mode 100644 index 00000000000..59f02c74a04 --- /dev/null +++ b/mysql-test/suite/innodb/r/dropdb_cs.result @@ -0,0 +1,16 @@ +# +# MDEV-28802 DROP DATABASE in InnoDB still is case-insensitive +# +SET @save_fpt=@@GLOBAL.innodb_file_per_table; +SET GLOBAL innodb_file_per_table=0; +CREATE DATABASE Db; +CREATE TABLE Db.t1 (c1 INT KEY) ENGINE=InnoDB; +CREATE DATABASE DB; +DROP DATABASE DB; +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'D%'; +NAME +Db/t1 +DROP DATABASE Db; +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'D%'; +TABLE_ID NAME FLAG N_COLS SPACE ROW_FORMAT ZIP_PAGE_SIZE SPACE_TYPE +SET GLOBAL innodb_file_per_table=@save_fpt; diff --git a/mysql-test/suite/innodb/t/dropdb_cs.test b/mysql-test/suite/innodb/t/dropdb_cs.test new file mode 100644 index 00000000000..0053ca732be --- /dev/null +++ b/mysql-test/suite/innodb/t/dropdb_cs.test @@ -0,0 +1,17 @@ +--source include/have_innodb.inc +--source include/have_case_sensitive_file_system.inc + +--echo # +--echo # MDEV-28802 DROP DATABASE in InnoDB still is case-insensitive +--echo # + +SET @save_fpt=@@GLOBAL.innodb_file_per_table; +SET GLOBAL innodb_file_per_table=0; +CREATE DATABASE Db; +CREATE TABLE Db.t1 (c1 INT KEY) ENGINE=InnoDB; +CREATE DATABASE DB; +DROP DATABASE DB; +SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'D%'; +DROP DATABASE Db; +SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'D%'; +SET GLOBAL innodb_file_per_table=@save_fpt; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 300a1cd83ae..b676f83b8a3 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1476,7 +1476,8 @@ static void innodb_drop_database(handlerton*, char *path) "WHILE 1 = 1 LOOP\n" " FETCH tab INTO tid,name;\n" " IF (SQL % NOTFOUND) THEN EXIT; END IF;\n" - " IF SUBSTR(name, 0, LENGTH(:db)) <> :db THEN EXIT; END IF;\n" + " IF TO_BINARY(SUBSTR(name, 0, LENGTH(:db))) <> TO_BINARY(:db)" + " THEN EXIT; END IF;\n" " DELETE FROM SYS_COLUMNS WHERE TABLE_ID=tid;\n" " DELETE FROM SYS_TABLES WHERE ID=tid;\n" " OPEN idx;\n"