@@ -104,7 +104,7 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
104104 QUERY PLAN
105105--------------------------------------------------------------------------------------------------------
106106 Foreign Scan (actual rows=1 loops=1)
107- AQO not used
107+ AQO: rows=1, error=0%
108108 Output: a.x, b.x
109109 Relations: (public.frgn a) INNER JOIN (public.frgn b)
110110 Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x = r2.x))))
@@ -113,6 +113,39 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE)
113113 JOINS: 0
114114(8 rows)
115115
116+ CREATE TABLE local_a(aid int primary key, aval text);
117+ CREATE TABLE local_b(bid int primary key, aid int references local_a(aid), bval text);
118+ INSERT INTO local_a SELECT i, 'val_' || i FROM generate_series(1,100) i;
119+ INSERT INTO local_b SELECT i, mod((i+random()*10)::numeric, 10) + 1, 'val_' || i FROM generate_series(1,1000) i;
120+ ANALYZE local_a, local_b;
121+ CREATE FOREIGN TABLE frgn_a(aid int, aval text) SERVER loopback OPTIONS (table_name 'local_a');
122+ CREATE FOREIGN TABLE frgn_b(bid int, aid int, bval text) SERVER loopback OPTIONS (table_name 'local_b');
123+ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
124+ SELECT * from frgn_a AS a, frgn_b AS b
125+ WHERE a.aid = b.aid AND b.bval like 'val%';
126+ QUERY PLAN
127+ -----------------------------------------------
128+ Foreign Scan (actual rows=1000 loops=1)
129+ AQO not used
130+ Relations: (frgn_a a) INNER JOIN (frgn_b b)
131+ Using aqo: true
132+ AQO mode: LEARN
133+ JOINS: 0
134+ (6 rows)
135+
136+ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
137+ SELECT * from frgn_a AS a, frgn_b AS b
138+ WHERE a.aid = b.aid AND b.bval like 'val%';
139+ QUERY PLAN
140+ -----------------------------------------------
141+ Foreign Scan (actual rows=1000 loops=1)
142+ AQO: rows=1000, error=0%
143+ Relations: (frgn_a a) INNER JOIN (frgn_b b)
144+ Using aqo: true
145+ AQO mode: LEARN
146+ JOINS: 0
147+ (6 rows)
148+
116149-- TODO: Non-mergejoinable join condition.
117150EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
118151SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
@@ -131,7 +164,7 @@ SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
131164 QUERY PLAN
132165--------------------------------------------------------------------------------------------------------
133166 Foreign Scan (actual rows=0 loops=1)
134- AQO not used
167+ AQO: rows=1, error=100%
135168 Output: a.x, b.x
136169 Relations: (public.frgn a) INNER JOIN (public.frgn b)
137170 Remote SQL: SELECT r1.x, r2.x FROM (public.local r1 INNER JOIN public.local r2 ON (((r1.x < r2.x))))
@@ -142,8 +175,12 @@ SELECT * FROM frgn AS a, frgn AS b WHERE a.x<b.x;
142175
143176DROP EXTENSION aqo CASCADE;
144177DROP EXTENSION postgres_fdw CASCADE;
145- NOTICE: drop cascades to3 other objects
178+ NOTICE: drop cascades to5 other objects
146179DETAIL: drop cascades to server loopback
147180drop cascades to user mapping for public on server loopback
148181drop cascades to foreign table frgn
182+ drop cascades to foreign table frgn_a
183+ drop cascades to foreign table frgn_b
149184DROP TABLE local;
185+ DROP TABLE local_b;
186+ DROP TABLE local_a;