Skip to content

Commit ab65966

Browse files
committed
Improve test coverage for MySQL binary, varbinary mapping to
PostgreSQL types. Rajkumar Raghuwanshi, reviewed by Suraj Kharage.
1 parent 4967253 commit ab65966

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

expected/select.out

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ CREATE FOREIGN TABLE f_test_tbl2 (c1 INTEGER, c2 VARCHAR(14), c3 VARCHAR(13))
3030
CREATE TYPE size_t AS enum('small','medium','large');
3131
CREATE FOREIGN TABLE f_enum_t1(id int, size size_t)
3232
SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'enum_t1');
33+
CREATE FOREIGN TABLE test5_1(c1 INT, c2 CHAR, c3 VARCHAR, c4 BOOLEAN, c5 TEXT, c6 INTERVAL, c7 BYTEA, c8 pg_catalog.DATE, c9 NUMERIC, c10 NAME)
34+
SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'test5');
35+
CREATE FOREIGN TABLE test5_2(c1 INT, c2 BYTEA, c3 BYTEA, c4 BYTEA, c5 BYTEA, c6 BYTEA, c7 BYTEA, c8 BYTEA, c9 BYTEA, c10 BYTEA)
36+
SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'test5');
3337
-- Insert data in MySQL db using foreign tables
3438
INSERT INTO f_test_tbl1 VALUES (100, 'EMP1', 'ADMIN', 1300, '1980-12-17', 800.23, NULL, 20);
3539
INSERT INTO f_test_tbl1 VALUES (200, 'EMP2', 'SALESMAN', 600, '1981-02-20', 1600.00, 300, 30);
@@ -1320,14 +1324,58 @@ SELECT attrelid::regclass, atttypid::regtype FROM pg_attribute
13201324
----------+----------
13211325
test5 | bytea
13221326
test5 | bytea
1323-
(2 rows)
1327+
test5 | bytea
1328+
test5 | bytea
1329+
test5 | bytea
1330+
test5 | bytea
1331+
test5 | bytea
1332+
test5 | bytea
1333+
test5 | bytea
1334+
(9 rows)
13241335

13251336
SELECT * FROM test5 ORDER BY 1;
1326-
c1 | c2 | c3
1327-
----+----------+--------
1328-
1 | \x610000 | \x6162
1337+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10
1338+
----+------+----------+------+------------------------+--------+------+------------------------+----+-----
1339+
1 | \x63 | \x633363 | \x74 | \x63356335633500000000 | \x3034 | \x31 | \x30312d31302d32303231 | | \x
1340+
(1 row)
1341+
1342+
-- Test Mapping of MySQL BINARY and VARBINARY data type with various
1343+
-- Postgres data types.
1344+
SELECT * FROM test5_1 ORDER BY 1;
1345+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10
1346+
----+----+-----+----+--------+----------+------+------------+----+-----
1347+
1 | c | c3c | t | c5c5c5 | @ 4 secs | \x31 | 2021-01-10 | |
13291348
(1 row)
13301349

1350+
SELECT * FROM test5_1 WHERE c9 IS NULL ORDER BY 1;
1351+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10
1352+
----+----+-----+----+--------+----------+------+------------+----+-----
1353+
1 | c | c3c | t | c5c5c5 | @ 4 secs | \x31 | 2021-01-10 | |
1354+
(1 row)
1355+
1356+
SELECT * FROM test5_1 WHERE c10 IS NULL ORDER BY 1;
1357+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10
1358+
----+----+----+----+----+----+----+----+----+-----
1359+
(0 rows)
1360+
1361+
-- Test MYSQL BINARY(n) and VARBINARY(n) variants mapping to Postgres BYTEA.
1362+
SELECT * FROM test5_2 ORDER BY 1;
1363+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10
1364+
----+------+----------+------+------------------------+--------+------+------------------------+----+-----
1365+
1 | \x63 | \x633363 | \x74 | \x63356335633500000000 | \x3034 | \x31 | \x30312d31302d32303231 | | \x
1366+
(1 row)
1367+
1368+
SELECT * FROM test5_2 WHERE c9 IS NULL ORDER BY 1;
1369+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10
1370+
----+------+----------+------+------------------------+--------+------+------------------------+----+-----
1371+
1 | \x63 | \x633363 | \x74 | \x63356335633500000000 | \x3034 | \x31 | \x30312d31302d32303231 | | \x
1372+
(1 row)
1373+
1374+
SELECT * FROM test5_2 WHERE c10 IS NULL ORDER BY 1;
1375+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10
1376+
----+----+----+----+----+----+----+----+----+-----
1377+
(0 rows)
1378+
13311379
-- FDW-400: Test the parameterized query by enabling use_remote_estimate
13321380
-- option.
13331381
ALTER SERVER mysql_svr options (SET use_remote_estimate 'true');
@@ -1373,6 +1421,8 @@ DROP FOREIGN TABLE f_mysql_test;
13731421
DROP FOREIGN TABLE f_enum_t1;
13741422
DROP FOREIGN TABLE f_test_tbl3;
13751423
DROP FOREIGN TABLE test5;
1424+
DROP FOREIGN TABLE test5_1;
1425+
DROP FOREIGN TABLE test5_2;
13761426
DROP TYPE size_t;
13771427
DROP TYPE enum_t1_size_t;
13781428
DROP TYPE enum_t2_size_t;

mysql_init.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e
5353
mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE test2 (c1 int PRIMARY KEY, c2 int, c3 varchar(255), c4 ENUM ('foo', 'bar', 'buz'))"
5454
mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE test3 (c1 int PRIMARY KEY, c2 int, c3 varchar(255))"
5555
mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE test4 (c1 int PRIMARY KEY, c2 int, c3 varchar(255))"
56-
mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE test5 (c1 int PRIMARY KEY, c2 binary(3), c3 varbinary(3))"
57-
mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "INSERT INTO test5 VALUES(1, 'a', 'ab');"
56+
mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "CREATE TABLE test5 (c1 int primary key, c2 binary, c3 binary(3), c4 binary(1), c5 binary(10), c6 varbinary(3), c7 varbinary(1), c8 varbinary(10), c9 binary(0), c10 varbinary(0));"
57+
mysql -h $MYSQL_HOST -u $MYSQL_USER_NAME -P $MYSQL_PORT -D mysql_fdw_regress -e "INSERT INTO test5 VALUES (1, 'c', 'c3c', 't', 'c5c5c5', '04', '1', '01-10-2021', NULL, '');"

sql/select.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ CREATE FOREIGN TABLE f_test_tbl2 (c1 INTEGER, c2 VARCHAR(14), c3 VARCHAR(13))
2929
CREATE TYPE size_t AS enum('small','medium','large');
3030
CREATE FOREIGN TABLE f_enum_t1(id int, size size_t)
3131
SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'enum_t1');
32+
CREATE FOREIGN TABLE test5_1(c1 INT, c2 CHAR, c3 VARCHAR, c4 BOOLEAN, c5 TEXT, c6 INTERVAL, c7 BYTEA, c8 pg_catalog.DATE, c9 NUMERIC, c10 NAME)
33+
SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'test5');
34+
CREATE FOREIGN TABLE test5_2(c1 INT, c2 BYTEA, c3 BYTEA, c4 BYTEA, c5 BYTEA, c6 BYTEA, c7 BYTEA, c8 BYTEA, c9 BYTEA, c10 BYTEA)
35+
SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'test5');
3236

3337
-- Insert data in MySQL db using foreign tables
3438
INSERT INTO f_test_tbl1 VALUES (100, 'EMP1', 'ADMIN', 1300, '1980-12-17', 800.23, NULL, 20);
@@ -388,6 +392,15 @@ IMPORT FOREIGN SCHEMA mysql_fdw_regress LIMIT TO ("test5")
388392
SELECT attrelid::regclass, atttypid::regtype FROM pg_attribute
389393
WHERE attrelid = 'test5'::regclass AND attnum > 1 ORDER BY 1;
390394
SELECT * FROM test5 ORDER BY 1;
395+
-- Test Mapping of MySQL BINARY and VARBINARY data type with various
396+
-- Postgres data types.
397+
SELECT * FROM test5_1 ORDER BY 1;
398+
SELECT * FROM test5_1 WHERE c9 IS NULL ORDER BY 1;
399+
SELECT * FROM test5_1 WHERE c10 IS NULL ORDER BY 1;
400+
-- Test MYSQL BINARY(n) and VARBINARY(n) variants mapping to Postgres BYTEA.
401+
SELECT * FROM test5_2 ORDER BY 1;
402+
SELECT * FROM test5_2 WHERE c9 IS NULL ORDER BY 1;
403+
SELECT * FROM test5_2 WHERE c10 IS NULL ORDER BY 1;
391404

392405
-- FDW-400: Test the parameterized query by enabling use_remote_estimate
393406
-- option.
@@ -417,6 +430,8 @@ DROP FOREIGN TABLE f_mysql_test;
417430
DROP FOREIGN TABLE f_enum_t1;
418431
DROP FOREIGN TABLE f_test_tbl3;
419432
DROP FOREIGN TABLE test5;
433+
DROP FOREIGN TABLE test5_1;
434+
DROP FOREIGN TABLE test5_2;
420435
DROP TYPE size_t;
421436
DROP TYPE enum_t1_size_t;
422437
DROP TYPE enum_t2_size_t;

0 commit comments

Comments
 (0)