Commit 7e7e12e7 authored by Oleg Smirnov's avatar Oleg Smirnov

MDEV-30765 SHOW TABLES not working properly with lower_case_table_names=2

lower_case_table_names=2 means "table names and database names are
stored as declared, but they are compared in lowercase".
But names of objects in grants are stored in lowercase for any value
of lower_case_table_names. This caused an error when checking grants
for objects containing uppercase letters since table_hash_search()
didn't take into account lower_case_table_names value
parent 8c6e314b
--lower-case-table-names=2
...@@ -14,7 +14,7 @@ SHOW CREATE TABLE T1; ...@@ -14,7 +14,7 @@ SHOW CREATE TABLE T1;
Table Create Table Table Create Table
T1 CREATE TABLE `T1` ( T1 CREATE TABLE `T1` (
`a` int(11) DEFAULT NULL `a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
RENAME TABLE T1 TO T2; RENAME TABLE T1 TO T2;
SHOW TABLES LIKE "T2"; SHOW TABLES LIKE "T2";
Tables_in_test (T2) Tables_in_test (T2)
...@@ -70,7 +70,7 @@ SHOW CREATE TABLE T1; ...@@ -70,7 +70,7 @@ SHOW CREATE TABLE T1;
Table Create Table Table Create Table
T1 CREATE TABLE `T1` ( T1 CREATE TABLE `T1` (
`a` int(11) DEFAULT NULL `a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
RENAME TABLE T1 TO T2; RENAME TABLE T1 TO T2;
SHOW TABLES LIKE "T2"; SHOW TABLES LIKE "T2";
Tables_in_test (T2) Tables_in_test (T2)
...@@ -319,18 +319,42 @@ Database (mysql_t%) ...@@ -319,18 +319,42 @@ Database (mysql_t%)
mysql_TEST mysql_TEST
show create database mysql_test; show create database mysql_test;
Database Create Database Database Create Database
mysql_test CREATE DATABASE `mysql_test` /*!40100 DEFAULT CHARACTER SET latin1 */ mysql_test CREATE DATABASE `mysql_test` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci */
show create database mysql_TEST; show create database mysql_TEST;
Database Create Database Database Create Database
mysql_TEST CREATE DATABASE `mysql_TEST` /*!40100 DEFAULT CHARACTER SET latin1 */ mysql_TEST CREATE DATABASE `mysql_TEST` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci */
show create table mysql_TEST.T1; show create table mysql_TEST.T1;
Table Create Table Table Create Table
T1 CREATE TABLE `T1` ( T1 CREATE TABLE `T1` (
`a` int(11) DEFAULT NULL `a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
show create table mysql_test.t1; show create table mysql_test.t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL `a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop database mysql_TEST; drop database mysql_TEST;
# MDEV-30765 SHOW TABLES not working properly with
# lower_case_table_names=2
#
create database db1;
use db1;
# lowercase table name
create table `a` (a int);
# uppercase table name
create table `B` (a int);
create user 'mysqltest_1'@'localhost' identified by 'password';
grant select, show view on db1.`a` to 'mysqltest_1'@'localhost';
grant select, show view on db1.`B` to 'mysqltest_1'@'localhost';
connect conn1, localhost, mysqltest_1, password, test;
connection conn1;
use db1;
show tables;
Tables_in_db1
B
a
connection default;
disconnect conn1;
drop user 'mysqltest_1'@'localhost';
drop tables a, B;
drop database db1;
...@@ -288,3 +288,29 @@ show create database mysql_TEST; ...@@ -288,3 +288,29 @@ show create database mysql_TEST;
show create table mysql_TEST.T1; show create table mysql_TEST.T1;
show create table mysql_test.t1; show create table mysql_test.t1;
drop database mysql_TEST; drop database mysql_TEST;
--echo # MDEV-30765 SHOW TABLES not working properly with
--echo # lower_case_table_names=2
--echo #
create database db1;
use db1;
--echo # lowercase table name
create table `a` (a int);
--echo # uppercase table name
create table `B` (a int);
create user 'mysqltest_1'@'localhost' identified by 'password';
grant select, show view on db1.`a` to 'mysqltest_1'@'localhost';
grant select, show view on db1.`B` to 'mysqltest_1'@'localhost';
connect (conn1, localhost, mysqltest_1, password, test);
connection conn1;
use db1;
show tables;
connection default;
disconnect conn1;
drop user 'mysqltest_1'@'localhost';
drop tables a, B;
drop database db1;
\ No newline at end of file
...@@ -5462,7 +5462,7 @@ table_hash_search(const char *host, const char *ip, const char *db, ...@@ -5462,7 +5462,7 @@ table_hash_search(const char *host, const char *ip, const char *db,
const char *user, const char *tname, bool exact) const char *user, const char *tname, bool exact)
{ {
return (GRANT_TABLE*) name_hash_search(&column_priv_hash, host, ip, db, return (GRANT_TABLE*) name_hash_search(&column_priv_hash, host, ip, db,
user, tname, exact, FALSE); user, tname, exact, (lower_case_table_names > 0));
} }
static bool column_priv_insert(GRANT_TABLE *grant) static bool column_priv_insert(GRANT_TABLE *grant)
......
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