Skip to content

Commit

Permalink
Add support for PostgreSQL 17 and EDB Postgres Advanced Server 17.
Browse files Browse the repository at this point in the history
Code changes involve adjusting calls to some server-side functions
due to their signature changes.

FDW-681, Suraj Kharage, reviewed by Sravan Velagandula.
  • Loading branch information
jeevanchalke committed Jun 15, 2024
1 parent dcfd737 commit 981970c
Show file tree
Hide file tree
Showing 5 changed files with 2,256 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ include $(PGXS)
ifndef MAJORVERSION
MAJORVERSION := $(basename $(VERSION))
endif
ifeq (,$(findstring $(MAJORVERSION), 12 13 14 15 16))
$(error PostgreSQL 12, 13, 14, 15, or 16 is required to compile this extension)
ifeq (,$(findstring $(MAJORVERSION), 12 13 14 15 16 17))
$(error PostgreSQL 12, 13, 14, 15, 16, or 17 is required to compile this extension)
endif

else
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This PostgreSQL extension implements a Foreign Data Wrapper (FDW) for
[MySQL][1].

Please note that this version of mysql_fdw works with PostgreSQL and EDB
Postgres Advanced Server 12, 13, 14, 15, and 16.
Postgres Advanced Server 12, 13, 14, 15, 16, and 17.

Installation
------------
Expand Down
275 changes: 275 additions & 0 deletions expected/limit_offset_pushdown_1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
\set MYSQL_HOST `echo \'"$MYSQL_HOST"\'`
\set MYSQL_PORT `echo \'"$MYSQL_PORT"\'`
\set MYSQL_USER_NAME `echo \'"$MYSQL_USER_NAME"\'`
\set MYSQL_PASS `echo \'"$MYSQL_PWD"\'`
-- Before running this file User must create database mysql_fdw_regress on
-- mysql with all permission for MYSQL_USER_NAME user with MYSQL_PWD password
-- and ran mysql_init.sh file to create tables.
\c contrib_regression
CREATE EXTENSION IF NOT EXISTS mysql_fdw;
CREATE SERVER mysql_svr FOREIGN DATA WRAPPER mysql_fdw
OPTIONS (host :MYSQL_HOST, port :MYSQL_PORT);
CREATE USER MAPPING FOR public SERVER mysql_svr
OPTIONS (username :MYSQL_USER_NAME, password :MYSQL_PASS);
-- Create foreign table
CREATE FOREIGN TABLE f_test_tbl2 (c1 INTEGER, c2 VARCHAR(14), c3 VARCHAR(13))
SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'test_tbl2');
INSERT INTO f_test_tbl2 VALUES(10, 'DEVELOPMENT', 'PUNE');
INSERT INTO f_test_tbl2 VALUES(20, 'ADMINISTRATION', 'BANGLORE');
INSERT INTO f_test_tbl2 VALUES(30, 'SALES', 'MUMBAI');
INSERT INTO f_test_tbl2 VALUES(40, 'HR', 'NAGPUR');
INSERT INTO f_test_tbl2 VALUES(50, 'IT', 'PUNE');
INSERT INTO f_test_tbl2 VALUES(60, 'DB SERVER', 'PUNE');
SELECT * FROM f_test_tbl2 ORDER BY 1;
c1 | c2 | c3
----+----------------+----------
10 | DEVELOPMENT | PUNE
20 | ADMINISTRATION | BANGLORE
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
60 | DB SERVER | PUNE
(6 rows)

-- LIMIT/OFFSET pushdown.
-- Limit with Offset should get pushdown.
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 3 OFFSET 2;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC LIMIT 3 OFFSET 2
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 3 OFFSET 2;
c1 | c2 | c3
----+-------+--------
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
(3 rows)

-- Only Limit should get pushdown.
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 3;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC LIMIT 3
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 3;
c1 | c2 | c3
----+----------------+----------
10 | DEVELOPMENT | PUNE
20 | ADMINISTRATION | BANGLORE
30 | SALES | MUMBAI
(3 rows)

-- Expression in Limit clause.
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT round(3.2) OFFSET 2;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC LIMIT 3 OFFSET 2
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT round(3.2) OFFSET 2;
c1 | c2 | c3
----+-------+--------
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
(3 rows)

-- Only Offset without Limit should not get pushdown.
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 OFFSET 2;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Limit
Output: c1, c2, c3
-> Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC
(5 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 OFFSET 2;
c1 | c2 | c3
----+-----------+--------
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
60 | DB SERVER | PUNE
(4 rows)

-- Limit ALL
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT ALL;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT ALL;
c1 | c2 | c3
----+----------------+----------
10 | DEVELOPMENT | PUNE
20 | ADMINISTRATION | BANGLORE
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
60 | DB SERVER | PUNE
(6 rows)

-- Limit NULL
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT NULL;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT NULL;
c1 | c2 | c3
----+----------------+----------
10 | DEVELOPMENT | PUNE
20 | ADMINISTRATION | BANGLORE
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
60 | DB SERVER | PUNE
(6 rows)

EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT NULL OFFSET 2;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Limit
Output: c1, c2, c3
-> Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC
(5 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT NULL OFFSET 2;
c1 | c2 | c3
----+-----------+--------
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
60 | DB SERVER | PUNE
(4 rows)

-- Limit 0 and Offset 0
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 0;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC LIMIT 0
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 0;
c1 | c2 | c3
----+----+----
(0 rows)

EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 0 OFFSET 0;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC LIMIT 0 OFFSET 0
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 0 OFFSET 0;
c1 | c2 | c3
----+----+----
(0 rows)

-- Offset NULL.
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 3 OFFSET NULL;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: c1, c2, c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC LIMIT 3
(3 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT 3 OFFSET NULL;
c1 | c2 | c3
----+----------------+----------
10 | DEVELOPMENT | PUNE
20 | ADMINISTRATION | BANGLORE
30 | SALES | MUMBAI
(3 rows)

-- Limit with placeholder.
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT (SELECT COUNT(*) FROM f_test_tbl2);
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Foreign Scan on public.f_test_tbl2
Output: f_test_tbl2.c1, f_test_tbl2.c2, f_test_tbl2.c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC LIMIT ?
InitPlan 1
-> Foreign Scan
Output: (count(*))
Relations: Aggregate on (mysql_fdw_regress.f_test_tbl2)
Remote query: SELECT count(*) FROM `mysql_fdw_regress`.`test_tbl2`
(8 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT (SELECT COUNT(*) FROM f_test_tbl2);
c1 | c2 | c3
----+----------------+----------
10 | DEVELOPMENT | PUNE
20 | ADMINISTRATION | BANGLORE
30 | SALES | MUMBAI
40 | HR | NAGPUR
50 | IT | PUNE
60 | DB SERVER | PUNE
(6 rows)

-- Limit with expression, should not pushdown.
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT (10 - (SELECT COUNT(*) FROM f_test_tbl2));
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Limit
Output: f_test_tbl2.c1, f_test_tbl2.c2, f_test_tbl2.c3
InitPlan 1
-> Foreign Scan
Output: (count(*))
Relations: Aggregate on (mysql_fdw_regress.f_test_tbl2)
Remote query: SELECT count(*) FROM `mysql_fdw_regress`.`test_tbl2`
-> Foreign Scan on public.f_test_tbl2
Output: f_test_tbl2.c1, f_test_tbl2.c2, f_test_tbl2.c3
Remote query: SELECT `c1`, `c2`, `c3` FROM `mysql_fdw_regress`.`test_tbl2` ORDER BY `c1` IS NULL, `c1` ASC
(10 rows)

SELECT * FROM f_test_tbl2 ORDER BY 1 LIMIT (10 - (SELECT COUNT(*) FROM f_test_tbl2));
c1 | c2 | c3
----+----------------+----------
10 | DEVELOPMENT | PUNE
20 | ADMINISTRATION | BANGLORE
30 | SALES | MUMBAI
40 | HR | NAGPUR
(4 rows)

DELETE FROM f_test_tbl2;
DROP FOREIGN TABLE f_test_tbl2;
DROP USER MAPPING FOR public SERVER mysql_svr;
DROP SERVER mysql_svr;
DROP EXTENSION mysql_fdw;
Loading

0 comments on commit 981970c

Please sign in to comment.