From 3af96b1e337ada137c1d7dc95209351faefa5a7f Mon Sep 17 00:00:00 2001 From: "Mark H. Wilkinson" Date: Wed, 9 Sep 2020 16:34:12 +0100 Subject: [PATCH 1/2] Test case for issue 202 --- expected/select.out | 11 +++++++++++ mysql_init.sh | 3 +++ sql/select.sql | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/expected/select.out b/expected/select.out index 4a53674..b115079 100644 --- a/expected/select.out +++ b/expected/select.out @@ -944,6 +944,17 @@ SELECT * FROM enum_t1 ORDER BY id; (3 rows) DROP FOREIGN TABLE enum_t1; +-- Issue #202 - correct handling of mixed-case table names. +IMPORT FOREIGN SCHEMA mysql_fdw_regress LIMIT TO ("mixedCaseTable") FROM SERVER mysql_svr INTO public; +SELECT * FROM "mixedCaseTable" ORDER BY id; + id | mixedCaseColumn +----+----------------- + 1 | small + 2 | medium + 3 | large +(3 rows) + +DROP FOREIGN TABLE "mixedCaseTable"; -- Cleanup DROP TABLE l_test_tbl1; DROP TABLE l_test_tbl2; diff --git a/mysql_init.sh b/mysql_init.sh index 2f1f27c..ac02ece 100755 --- a/mysql_init.sh +++ b/mysql_init.sh @@ -29,6 +29,7 @@ mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress1 -e "DROP TABLE IF EXISTS student;" mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress1 -e "DROP TABLE IF EXISTS numbers;" mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "DROP TABLE IF EXISTS enum_t1;" +mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "DROP TABLE IF EXISTS mixedCaseTable;" mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE mysql_test(a int primary key, b int);" mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "INSERT INTO mysql_test(a,b) VALUES (1,1);" @@ -40,3 +41,5 @@ mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress1 -e mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress1 -e "CREATE TABLE numbers (a int, b varchar(255));" mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE enum_t1 (id int PRIMARY KEY, size ENUM('small', 'medium', 'large'));" mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "INSERT INTO enum_t1 VALUES (1, 'small'),(2, 'medium'),(3, 'medium');" +mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE mixedCaseTable (id int PRIMARY KEY, mixedCaseColumn text);" +mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "INSERT INTO mixedCaseTable VALUES (1, 'small'),(2, 'medium'),(3, 'large');" diff --git a/sql/select.sql b/sql/select.sql index 25c7f56..2f3524d 100644 --- a/sql/select.sql +++ b/sql/select.sql @@ -237,6 +237,11 @@ IMPORT FOREIGN SCHEMA mysql_fdw_regress LIMIT TO (enum_t1) FROM SERVER mysql_svr SELECT * FROM enum_t1 ORDER BY id; DROP FOREIGN TABLE enum_t1; +-- Issue #202 - correct handling of mixed-case table names. +IMPORT FOREIGN SCHEMA mysql_fdw_regress LIMIT TO ("mixedCaseTable") FROM SERVER mysql_svr INTO public; +SELECT * FROM "mixedCaseTable" ORDER BY id; +DROP FOREIGN TABLE "mixedCaseTable"; + -- Cleanup DROP TABLE l_test_tbl1; DROP TABLE l_test_tbl2; From 32c7ee8964affbb51cacd3868fa82d76607b44c7 Mon Sep 17 00:00:00 2001 From: "Mark H. Wilkinson" Date: Wed, 9 Sep 2020 16:46:10 +0100 Subject: [PATCH 2/2] Make IMPORT FOREIGN SCHEMA behave consistently The case of the table names returned by information_schema queries depends on MySQL's `lower_case_table_names` setting. https://dev.mysql.com/doc/refman/5.7/en/charset-collation-information-schema.html suggests forcing a suitable collation to work around the issue. Fixes #202. --- mysql_fdw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql_fdw.c b/mysql_fdw.c index 864cbc7..79a5622 100644 --- a/mysql_fdw.c +++ b/mysql_fdw.c @@ -1699,7 +1699,7 @@ mysqlImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid) { bool first_item = true; - appendStringInfoString(&buf, " AND t.TABLE_NAME "); + appendStringInfoString(&buf, " AND t.TABLE_NAME COLLATE UTF8_GENERAL_CI "); if (stmt->list_type == FDW_IMPORT_SCHEMA_EXCEPT) appendStringInfoString(&buf, "NOT "); appendStringInfoString(&buf, "IN (");