From 7fe764b10953c53c6bd1d4b80222f7765c1c2d44 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 22 Apr 2024 22:51:23 +0200 Subject: [PATCH] MDEV-32973 SHOW TABLES LIKE shows temporary tables with non-matching names * compare both db and table name * use the correct charset --- mysql-test/main/lowercase_fs_off.result | 23 +++++++++++++++++ mysql-test/main/lowercase_fs_off.test | 16 ++++++++++++ mysql-test/main/lowercase_table2.result | 33 +++++++++++++++++++++++++ mysql-test/main/lowercase_table2.test | 21 ++++++++++++++++ mysql-test/suite/rpl/r/rpl_ddl.result | 1 - sql/sql_show.cc | 31 ++++++++++++++++++----- 6 files changed, 118 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/lowercase_fs_off.result b/mysql-test/main/lowercase_fs_off.result index f59470ae0bc..255c6f85f82 100644 --- a/mysql-test/main/lowercase_fs_off.result +++ b/mysql-test/main/lowercase_fs_off.result @@ -271,3 +271,26 @@ CREATE TABLE t1 (a Mariadb_schema.date); ERROR HY000: Unknown data type: 'Mariadb_schema.date' CREATE TABLE t1 (a mariadb_schema.date); DROP TABLE t1; +# End of 10.3 tests +# +# MDEV-32973 SHOW TABLES LIKE shows temporary tables with non-matching names +# +create temporary table t1 (a int); +create temporary table t2 (a int); +create temporary table T1 (a int); +show tables like 't1'; +Tables_in_test (t1) +t1 +select table_name from information_schema.tables where table_schema='test' + and table_name='t1'; +table_name +t1 +show tables like '_1'; +Tables_in_test (_1) +T1 +t1 +show tables like 't%'; +Tables_in_test (t%) +t2 +t1 +# End of 11.2 tests diff --git a/mysql-test/main/lowercase_fs_off.test b/mysql-test/main/lowercase_fs_off.test index 172566a1365..4bff916db83 100644 --- a/mysql-test/main/lowercase_fs_off.test +++ b/mysql-test/main/lowercase_fs_off.test @@ -146,3 +146,19 @@ CREATE TABLE t1 (a Mariadb_schema.date); CREATE TABLE t1 (a mariadb_schema.date); DROP TABLE t1; + +--echo # End of 10.3 tests + +--echo # +--echo # MDEV-32973 SHOW TABLES LIKE shows temporary tables with non-matching names +--echo # +create temporary table t1 (a int); +create temporary table t2 (a int); +create temporary table T1 (a int); +show tables like 't1'; +select table_name from information_schema.tables where table_schema='test' + and table_name='t1'; +show tables like '_1'; +show tables like 't%'; + +--echo # End of 11.2 tests diff --git a/mysql-test/main/lowercase_table2.result b/mysql-test/main/lowercase_table2.result index 3a4c46eb776..3307046bafa 100644 --- a/mysql-test/main/lowercase_table2.result +++ b/mysql-test/main/lowercase_table2.result @@ -377,3 +377,36 @@ SHOW CREATE DATABASE db1; Database Create Database db1 CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci */ DROP DATABASE Db1; +USE test; +# End of 10.4 tests +# +# MDEV-32973 SHOW TABLES LIKE shows temporary tables with non-matching names +# +create temporary table t2 (a int); +create temporary table T1 (a int); +show tables; +Tables_in_test +t1 +t2 +show tables like 't1'; +Tables_in_test (t1) +t1 +show tables like 'T1'; +Tables_in_test (T1) +t1 +select table_name from information_schema.tables where table_schema='test' + and table_name='t1'; +table_name +t1 +select table_name from information_schema.tables where table_schema='test' + and table_name='T1'; +table_name +t1 +show tables like '_1'; +Tables_in_test (_1) +t1 +show tables like 't%'; +Tables_in_test (t%) +t1 +t2 +# End of 11.2 tests diff --git a/mysql-test/main/lowercase_table2.test b/mysql-test/main/lowercase_table2.test index 5d595e96230..342072e60b4 100644 --- a/mysql-test/main/lowercase_table2.test +++ b/mysql-test/main/lowercase_table2.test @@ -328,3 +328,24 @@ ALTER DATABASE Db1 DEFAULT CHARACTER SET utf8; SHOW CREATE DATABASE Db1; SHOW CREATE DATABASE db1; DROP DATABASE Db1; +USE test; + +--echo # End of 10.4 tests + +--echo # +--echo # MDEV-32973 SHOW TABLES LIKE shows temporary tables with non-matching names +--echo # +# temp tables don't preserve the letter case despite lower-case-table-names=2 +create temporary table t2 (a int); +create temporary table T1 (a int); +show tables; +show tables like 't1'; +show tables like 'T1'; +select table_name from information_schema.tables where table_schema='test' + and table_name='t1'; +select table_name from information_schema.tables where table_schema='test' + and table_name='T1'; +show tables like '_1'; +show tables like 't%'; + +--echo # End of 11.2 tests diff --git a/mysql-test/suite/rpl/r/rpl_ddl.result b/mysql-test/suite/rpl/r/rpl_ddl.result index 2de5b0228b7..27d84fea1e4 100644 --- a/mysql-test/suite/rpl/r/rpl_ddl.result +++ b/mysql-test/suite/rpl/r/rpl_ddl.result @@ -343,7 +343,6 @@ TEST-INFO: SLAVE: The INSERT is committed (Succeeded) connection master; SHOW TABLES LIKE 't2'; Tables_in_mysqltest1 (t2) -t23 connection slave; SHOW TABLES LIKE 't2'; Tables_in_mysqltest1 (t2) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 97a0594959a..4a7cf893de4 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -5215,6 +5215,20 @@ public: }; +static bool wildcmpcs(const LEX_CSTRING &str, const LEX_CSTRING &pat) +{ + return table_alias_charset->wildcmp(str.str, str.str + str.length, + pat.str, pat.str + pat.length, + '\\', '_', '%'); +} + +static bool strcmpcs(const LEX_CSTRING &str, const LEX_CSTRING &pat) +{ + return table_alias_charset->strnncoll(str.str, str.length, + pat.str, pat.length, 0); +} + + /** @brief Fill I_S tables whose data are retrieved from frm files and storage engine @@ -5346,15 +5360,20 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) { All_tmp_tables_list::Iterator it(*open_tables_state_backup.temporary_tables); TMP_TABLE_SHARE *share_temp; - const char *lookup_db= plan->lookup_field_vals.db_value.str; - int (*cmp)(CHARSET_INFO *, const char *, const char *)= - plan->lookup_field_vals.wild_db_value - ? wild_case_compare : system_charset_info->coll->strcasecmp; + bool (*cmp_db)(const LEX_CSTRING &, const LEX_CSTRING &)= + plan->lookup_field_vals.wild_db_value ? wildcmpcs : strcmpcs; + bool (*cmp_table)(const LEX_CSTRING &, const LEX_CSTRING &)= + plan->lookup_field_vals.wild_table_value ? wildcmpcs : strcmpcs; while ((share_temp= it++)) { - if (lookup_db) + if (plan->lookup_field_vals.db_value.str) { - if (cmp(system_charset_info, share_temp->db.str, lookup_db)) + if (cmp_db(share_temp->db, plan->lookup_field_vals.db_value)) + continue; + } + if (plan->lookup_field_vals.table_value.str) + { + if (cmp_table(share_temp->table_name, plan->lookup_field_vals.table_value)) continue; }