@@ -57,11 +57,6 @@ SELECT x FROM frgn;
57
57
(5 rows)
58
58
59
59
-- Push down base filters. Use verbose mode to see filters.
60
- EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE))
61
- SELECT x FROM frgn WHERE x < 10;
62
- ERROR: syntax error at or near ")"
63
- LINE 1: ...LAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE))
64
- ^
65
60
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
66
61
SELECT x FROM frgn WHERE x < 10;
67
62
QUERY PLAN
@@ -75,6 +70,19 @@ SELECT x FROM frgn WHERE x < 10;
75
70
JOINS: 0
76
71
(7 rows)
77
72
73
+ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
74
+ SELECT x FROM frgn WHERE x < 10;
75
+ QUERY PLAN
76
+ -----------------------------------------------------------
77
+ Foreign Scan on public.frgn (actual rows=1 loops=1)
78
+ AQO: rows=1, error=0%
79
+ Output: x
80
+ Remote SQL: SELECT x FROM public.local WHERE ((x < 10))
81
+ Using aqo: true
82
+ AQO mode: LEARN
83
+ JOINS: 0
84
+ (7 rows)
85
+
78
86
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
79
87
SELECT x FROM frgn WHERE x < -10; -- AQO ignores constants
80
88
QUERY PLAN
@@ -125,6 +133,39 @@ SELECT * FROM frgn AS a, frgn AS b WHERE a.x=b.x;
125
133
JOINS: 0
126
134
(8 rows)
127
135
136
+ CREATE TABLE local_a(aid int primary key, aval text);
137
+ CREATE TABLE local_b(bid int primary key, aid int references local_a(aid), bval text);
138
+ INSERT INTO local_a SELECT i, 'val_' || i FROM generate_series(1,100) i;
139
+ INSERT INTO local_b SELECT i, mod((i+random()*10)::numeric, 10) + 1, 'val_' || i FROM generate_series(1,1000) i;
140
+ ANALYZE local_a, local_b;
141
+ CREATE FOREIGN TABLE frgn_a(aid int, aval text) SERVER loopback OPTIONS (table_name 'local_a');
142
+ CREATE FOREIGN TABLE frgn_b(bid int, aid int, bval text) SERVER loopback OPTIONS (table_name 'local_b');
143
+ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
144
+ SELECT * from frgn_a AS a, frgn_b AS b
145
+ WHERE a.aid = b.aid AND b.bval like 'val%';
146
+ QUERY PLAN
147
+ -----------------------------------------------
148
+ Foreign Scan (actual rows=1000 loops=1)
149
+ AQO not used
150
+ Relations: (frgn_a a) INNER JOIN (frgn_b b)
151
+ Using aqo: true
152
+ AQO mode: LEARN
153
+ JOINS: 0
154
+ (6 rows)
155
+
156
+ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
157
+ SELECT * from frgn_a AS a, frgn_b AS b
158
+ WHERE a.aid = b.aid AND b.bval like 'val%';
159
+ QUERY PLAN
160
+ -----------------------------------------------
161
+ Foreign Scan (actual rows=1000 loops=1)
162
+ AQO: rows=1000, error=0%
163
+ Relations: (frgn_a a) INNER JOIN (frgn_b b)
164
+ Using aqo: true
165
+ AQO mode: LEARN
166
+ JOINS: 0
167
+ (6 rows)
168
+
128
169
-- TODO: Non-mergejoinable join condition.
129
170
EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
130
171
SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
@@ -143,7 +184,7 @@ SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
143
184
QUERY PLAN
144
185
--------------------------------------------------------------------------------------------------------
145
186
Foreign Scan (actual rows=0 loops=1)
146
- AQO not used
187
+ AQO: rows=1, error=100%
147
188
Output: a.x, b.x
148
189
Relations: (public.frgn a) INNER JOIN (public.frgn b)
149
190
Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x < r2.x))))
@@ -154,8 +195,12 @@ SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
154
195
155
196
DROP EXTENSION aqo CASCADE;
156
197
DROP EXTENSION postgres_fdw CASCADE;
157
- NOTICE: drop cascades to 3 other objects
198
+ NOTICE: drop cascades to 5 other objects
158
199
DETAIL: drop cascades to server loopback
159
200
drop cascades to user mapping for public on server loopback
160
201
drop cascades to foreign table frgn
202
+ drop cascades to foreign table frgn_a
203
+ drop cascades to foreign table frgn_b
161
204
DROP TABLE local;
205
+ DROP TABLE local_b;
206
+ DROP TABLE local_a;
0 commit comments