File: limit_offset_pushdown.out

package info (click to toggle)
postgresql-mysql-fdw 2.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,272 kB
  • sloc: ansic: 5,926; sql: 1,987; sh: 84; makefile: 42
file content (275 lines) | stat: -rw-r--r-- 11,397 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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 (returns $0)
     ->  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 (returns $0)
     ->  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;