diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out index 9ad9795..fa3400d 100644 --- a/contrib/postgres_fdw/expected/postgres_fdw.out +++ b/contrib/postgres_fdw/expected/postgres_fdw.out @@ -827,8 +827,8 @@ EXPLAIN (VERBOSE, COSTS OFF) QUERY PLAN ------------------------------------------------------------------------------- Sort - Output: c1, c2, c3, c4, c5, c6, c7, c8, (random()) - Sort Key: ft2.c1, (random()) + Output: c1, c2, c3, c4, c5, c6, c7, c8, random() + Sort Key: ft2.c1, random() -> Foreign Scan on public.ft2 Output: c1, c2, c3, c4, c5, c6, c7, c8, random() Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" @@ -839,7 +839,7 @@ EXPLAIN (VERBOSE, COSTS OFF) QUERY PLAN ------------------------------------------------------------------------------- Sort - Output: c1, c2, c3, c4, c5, c6, c7, c8, ((c3)::text) + Output: c1, c2, c3, c4, c5, c6, c7, c8, (c3)::text Sort Key: ft2.c1, ft2.c3 COLLATE "C" -> Foreign Scan on public.ft2 Output: c1, c2, c3, c4, c5, c6, c7, c8, c3 @@ -864,7 +864,7 @@ EXPLAIN (VERBOSE, COSTS OFF) QUERY PLAN --------------------------------------------------------------------------- Foreign Scan - Output: (count(c3)) + Output: count(c3) Relations: Aggregate on (public.ft1 t1) Remote SQL: SELECT count(c3) FROM "S 1"."T 1" WHERE (("C 1" = abs(c2))) (4 rows) @@ -880,7 +880,7 @@ EXPLAIN (VERBOSE, COSTS OFF) QUERY PLAN ---------------------------------------------------------------------- Foreign Scan - Output: (count(c3)) + Output: count(c3) Relations: Aggregate on (public.ft1 t1) Remote SQL: SELECT count(c3) FROM "S 1"."T 1" WHERE (("C 1" = c2)) (4 rows) @@ -938,7 +938,7 @@ EXPLAIN (VERBOSE, COSTS OFF) QUERY PLAN ----------------------------------------------------------------------------------------------- Foreign Scan - Output: (count(c3)) + Output: count(c3) Relations: Aggregate on (public.ft1 t1) Remote SQL: SELECT count(c3) FROM "S 1"."T 1" WHERE (("C 1" = public.postgres_fdw_abs(c2))) (4 rows) @@ -954,7 +954,7 @@ EXPLAIN (VERBOSE, COSTS OFF) QUERY PLAN ----------------------------------------------------------------------------------------- Foreign Scan - Output: (count(c3)) + Output: count(c3) Relations: Aggregate on (public.ft1 t1) Remote SQL: SELECT count(c3) FROM "S 1"."T 1" WHERE (("C 1" OPERATOR(public.===) c2)) (4 rows) @@ -2065,13 +2065,13 @@ SELECT q.a, ft2.c1 FROM (SELECT 13 FROM ft1 WHERE c1 = 13) q(a) RIGHT JOIN ft2 O QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- Nested Loop Left Join - Output: (13), ft2.c1 + Output: 13, ft2.c1 Join Filter: (13 = ft2.c1) -> Foreign Scan on public.ft2 Output: ft2.c1 Remote SQL: SELECT "C 1" FROM "S 1"."T 1" WHERE (("C 1" >= 10)) AND (("C 1" <= 15)) ORDER BY "C 1" ASC NULLS LAST -> Materialize - Output: (13) + Output: 13 -> Foreign Scan on public.ft1 Output: 13 Remote SQL: SELECT NULL FROM "S 1"."T 1" WHERE (("C 1" = 13)) @@ -2094,13 +2094,13 @@ SELECT ft4.c1, q.* FROM ft4 LEFT JOIN (SELECT 13, ft1.c1, ft2.c1 FROM ft1 RIGHT QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop Left Join - Output: ft4.c1, (13), ft1.c1, ft2.c1 + Output: ft4.c1, 13, ft1.c1, ft2.c1 Join Filter: (ft4.c1 = ft1.c1) -> Foreign Scan on public.ft4 Output: ft4.c1, ft4.c2, ft4.c3 Remote SQL: SELECT c1 FROM "S 1"."T 3" WHERE ((c1 >= 10)) AND ((c1 <= 15)) -> Materialize - Output: ft1.c1, ft2.c1, (13) + Output: ft1.c1, ft2.c1, 13 -> Foreign Scan Output: ft1.c1, ft2.c1, 13 Relations: (public.ft1) INNER JOIN (public.ft2) @@ -2287,12 +2287,12 @@ select count(c6), sum(c1), avg(c1), min(c2), max(c1), stddev(c2), sum(c1) * (ran QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------- Result - Output: (count(c6)), (sum(c1)), (avg(c1)), (min(c2)), (max(c1)), (stddev(c2)), ((sum(c1)) * ((random() <= '1'::double precision))::integer), c2 + Output: count(c6), sum(c1), avg(c1), min(c2), max(c1), stddev(c2), (sum(c1) * ((random() <= '1'::double precision))::integer), c2 -> Sort - Output: (count(c6)), (sum(c1)), (avg(c1)), (min(c2)), (max(c1)), (stddev(c2)), c2 - Sort Key: (count(ft1.c6)), (sum(ft1.c1)) + Output: count(c6), sum(c1), avg(c1), min(c2), max(c1), stddev(c2), c2 + Sort Key: count(ft1.c6), sum(ft1.c1) -> Foreign Scan - Output: (count(c6)), (sum(c1)), (avg(c1)), (min(c2)), (max(c1)), (stddev(c2)), c2 + Output: count(c6), sum(c1), avg(c1), min(c2), max(c1), stddev(c2), c2 Relations: Aggregate on (public.ft1) Remote SQL: SELECT count(c6), sum("C 1"), avg("C 1"), min(c2), max("C 1"), stddev(c2), c2 FROM "S 1"."T 1" WHERE ((c2 < 5)) GROUP BY c2 (9 rows) @@ -2325,7 +2325,7 @@ select count(*), sum(t1.c1), avg(t2.c1) from ft1 t1 inner join ft1 t2 on (t1.c2 QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: (count(*)), (sum(t1.c1)), (avg(t2.c1)) + Output: count(*), sum(t1.c1), avg(t2.c1) Relations: Aggregate on ((public.ft1 t1) INNER JOIN (public.ft1 t2)) Remote SQL: SELECT count(*), sum(r1."C 1"), avg(r2."C 1") FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r2.c2 = 6)) AND ((r1.c2 = 6)))) (4 rows) @@ -2356,10 +2356,10 @@ select c2/2, sum(c2) * (c2/2) from ft1 group by c2/2 order by c2/2; QUERY PLAN ------------------------------------------------------------------------------------------------ Sort - Output: ((c2 / 2)), ((sum(c2) * (c2 / 2))) - Sort Key: ((ft1.c2 / 2)) + Output: (c2 / 2), (sum(c2) * (c2 / 2)) + Sort Key: (ft1.c2 / 2) -> Foreign Scan - Output: ((c2 / 2)), ((sum(c2) * (c2 / 2))) + Output: (c2 / 2), (sum(c2) * (c2 / 2)) Relations: Aggregate on (public.ft1) Remote SQL: SELECT (c2 / 2), (sum(c2) * (c2 / 2)) FROM "S 1"."T 1" GROUP BY ((c2 / 2)) (7 rows) @@ -2382,10 +2382,10 @@ select count(x.a), sum(x.a) from (select c2 a, sum(c1) b from ft1 group by c2, s Aggregate Output: count(ft1.c2), sum(ft1.c2) -> Sort - Output: ft1.c2, (sum(ft1.c1)), (sqrt((ft1.c1)::double precision)) - Sort Key: ft1.c2, (sum(ft1.c1)) + Output: ft1.c2, sum(ft1.c1), sqrt((ft1.c1)::double precision) + Sort Key: ft1.c2, sum(ft1.c1) -> Foreign Scan - Output: ft1.c2, (sum(ft1.c1)), (sqrt((ft1.c1)::double precision)) + Output: ft1.c2, sum(ft1.c1), sqrt((ft1.c1)::double precision) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c2, sum("C 1"), sqrt("C 1") FROM "S 1"."T 1" GROUP BY c2, (sqrt("C 1")) (9 rows) @@ -2399,13 +2399,13 @@ select count(x.a), sum(x.a) from (select c2 a, sum(c1) b from ft1 group by c2, s -- Aggregate is still pushed down by taking unshippable expression out explain (verbose, costs off) select c2 * (random() <= 1)::int as sum1, sum(c1) * c2 as sum2 from ft1 group by c2 order by 1, 2; - QUERY PLAN ---------------------------------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------------------------------------- Sort - Output: ((c2 * ((random() <= '1'::double precision))::integer)), ((sum(c1) * c2)), c2 - Sort Key: ((ft1.c2 * ((random() <= '1'::double precision))::integer)), ((sum(ft1.c1) * ft1.c2)) + Output: (c2 * ((random() <= '1'::double precision))::integer), (sum(c1) * c2), c2 + Sort Key: (ft1.c2 * ((random() <= '1'::double precision))::integer), (sum(ft1.c1) * ft1.c2) -> Foreign Scan - Output: (c2 * ((random() <= '1'::double precision))::integer), ((sum(c1) * c2)), c2 + Output: (c2 * ((random() <= '1'::double precision))::integer), (sum(c1) * c2), c2 Relations: Aggregate on (public.ft1) Remote SQL: SELECT (sum("C 1") * c2), c2 FROM "S 1"."T 1" GROUP BY c2 (7 rows) @@ -2431,10 +2431,10 @@ select c2 * (random() <= 1)::int as c2 from ft2 group by c2 * (random() <= 1)::i QUERY PLAN ------------------------------------------------------------------------------ Sort - Output: ((c2 * ((random() <= '1'::double precision))::integer)) - Sort Key: ((ft2.c2 * ((random() <= '1'::double precision))::integer)) + Output: (c2 * ((random() <= '1'::double precision))::integer) + Sort Key: (ft2.c2 * ((random() <= '1'::double precision))::integer) -> HashAggregate - Output: ((c2 * ((random() <= '1'::double precision))::integer)) + Output: (c2 * ((random() <= '1'::double precision))::integer) Group Key: (ft2.c2 * ((random() <= '1'::double precision))::integer) -> Foreign Scan on public.ft2 Output: (c2 * ((random() <= '1'::double precision))::integer) @@ -2447,10 +2447,10 @@ select count(c2) w, c2 x, 5 y, 7.0 z from ft1 group by 2, y, 9.0::int order by 2 QUERY PLAN ---------------------------------------------------------------------------------------------------------- Sort - Output: (count(c2)), c2, (5), (7.0), (9) + Output: count(c2), c2, 5, 7.0, 9 Sort Key: ft1.c2 -> Foreign Scan - Output: (count(c2)), c2, (5), (7.0), (9) + Output: count(c2), c2, 5, 7.0, 9 Relations: Aggregate on (public.ft1) Remote SQL: SELECT count(c2), c2, 5, 7.0, 9 FROM "S 1"."T 1" GROUP BY c2, 5::integer, 9::integer (7 rows) @@ -2476,10 +2476,10 @@ select c2, sum(c1) from ft2 group by c2 having avg(c1) < 500 and sum(c1) < 49800 QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------- Sort - Output: c2, (sum(c1)) + Output: c2, sum(c1) Sort Key: ft2.c2 -> Foreign Scan - Output: c2, (sum(c1)) + Output: c2, sum(c1) Relations: Aggregate on (public.ft2) Remote SQL: SELECT c2, sum("C 1") FROM "S 1"."T 1" GROUP BY c2 HAVING ((avg("C 1") < 500::numeric)) AND ((sum("C 1") < 49800)) (7 rows) @@ -2497,10 +2497,10 @@ select c5, count(c2) from ft1 group by c5, sqrt(c2) having sqrt(max(c2)) = sqrt( QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort - Output: c5, (count(c2)), (sqrt((c2)::double precision)) - Sort Key: ft1.c5, (count(ft1.c2)) + Output: c5, count(c2), sqrt((c2)::double precision) + Sort Key: ft1.c5, count(ft1.c2) -> Foreign Scan - Output: c5, (count(c2)), (sqrt((c2)::double precision)) + Output: c5, count(c2), sqrt((c2)::double precision) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c5, count(c2), sqrt(c2) FROM "S 1"."T 1" GROUP BY c5, (sqrt(c2)) HAVING ((sqrt(max(c2)) = 1.41421356237309515::double precision)) (7 rows) @@ -2528,8 +2528,8 @@ select count(*) from (select c5, count(c1) from ft1 group by c5, sqrt(c2) having Aggregate Output: count(*) -> Foreign Scan - Output: ft1.c5, (NULL::bigint), (sqrt((ft1.c2)::double precision)) - Filter: (((((avg(ft1.c1)) / (avg(ft1.c1))))::double precision * random()) <= '1'::double precision) + Output: ft1.c5, NULL::bigint, sqrt((ft1.c2)::double precision) + Filter: ((((avg(ft1.c1) / avg(ft1.c1)))::double precision * random()) <= '1'::double precision) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c5, NULL::bigint, sqrt(c2), avg("C 1") FROM "S 1"."T 1" GROUP BY c5, (sqrt(c2)) HAVING ((avg("C 1") < 500::numeric)) (7 rows) @@ -2564,10 +2564,10 @@ select array_agg(c1 order by c1) from ft1 where c1 < 100 group by c2 order by 1; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------- Sort - Output: (array_agg(c1 ORDER BY c1)), c2 - Sort Key: (array_agg(ft1.c1 ORDER BY ft1.c1)) + Output: array_agg(c1 ORDER BY c1), c2 + Sort Key: array_agg(ft1.c1 ORDER BY ft1.c1) -> Foreign Scan - Output: (array_agg(c1 ORDER BY c1)), c2 + Output: array_agg(c1 ORDER BY c1), c2 Relations: Aggregate on (public.ft1) Remote SQL: SELECT array_agg("C 1" ORDER BY "C 1" ASC NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" < 100)) GROUP BY c2 (7 rows) @@ -2593,7 +2593,7 @@ select array_agg(c5 order by c1 desc) from ft2 where c2 = 6 and c1 < 50; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: (array_agg(c5 ORDER BY c1 DESC)) + Output: array_agg(c5 ORDER BY c1 DESC) Relations: Aggregate on (public.ft2) Remote SQL: SELECT array_agg(c5 ORDER BY "C 1" DESC NULLS FIRST) FROM "S 1"."T 1" WHERE (("C 1" < 50)) AND ((c2 = 6)) (4 rows) @@ -2610,10 +2610,10 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2 QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort - Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3)) - Sort Key: (array_agg(DISTINCT (t1.c1 % 5))) + Output: array_agg(DISTINCT (t1.c1 % 5)), (t2.c1 % 3) + Sort Key: array_agg(DISTINCT (t1.c1 % 5)) -> Foreign Scan - Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3)) + Output: array_agg(DISTINCT (t1.c1 % 5)), (t2.c1 % 3) Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2)) Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY ((r2.c1 % 3)) (7 rows) @@ -2631,10 +2631,10 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Sort - Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3)) - Sort Key: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))) + Output: array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5)), (t2.c1 % 3) + Sort Key: array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5)) -> Foreign Scan - Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3)) + Output: array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5)), (t2.c1 % 3) Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2)) Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY ((r2.c1 % 3)) (7 rows) @@ -2651,10 +2651,10 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort - Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3)) - Sort Key: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)) + Output: array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST), (t2.c1 % 3) + Sort Key: array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST) -> Foreign Scan - Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3)) + Output: array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST), (t2.c1 % 3) Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2)) Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY ((r2.c1 % 3)) (7 rows) @@ -2672,10 +2672,10 @@ select sum(c1) filter (where c1 < 100 and c2 > 5) from ft1 group by c2 order by QUERY PLAN -------------------------------------------------------------------------------------------------------------------- Sort - Output: (sum(c1) FILTER (WHERE ((c1 < 100) AND (c2 > 5)))), c2 - Sort Key: (sum(ft1.c1) FILTER (WHERE ((ft1.c1 < 100) AND (ft1.c2 > 5)))) + Output: sum(c1) FILTER (WHERE ((c1 < 100) AND (c2 > 5))), c2 + Sort Key: sum(ft1.c1) FILTER (WHERE ((ft1.c1 < 100) AND (ft1.c2 > 5))) -> Foreign Scan - Output: (sum(c1) FILTER (WHERE ((c1 < 100) AND (c2 > 5)))), c2 + Output: sum(c1) FILTER (WHERE ((c1 < 100) AND (c2 > 5))), c2 Relations: Aggregate on (public.ft1) Remote SQL: SELECT sum("C 1") FILTER (WHERE (("C 1" < 100) AND (c2 > 5))), c2 FROM "S 1"."T 1" GROUP BY c2 (7 rows) @@ -2701,7 +2701,7 @@ select sum(c1%3), sum(distinct c1%3 order by c1%3) filter (where c1%3 < 2), c2 f QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: (sum((c1 % 3))), (sum(DISTINCT (c1 % 3) ORDER BY (c1 % 3)) FILTER (WHERE ((c1 % 3) < 2))), c2 + Output: sum((c1 % 3)), sum(DISTINCT (c1 % 3) ORDER BY (c1 % 3)) FILTER (WHERE ((c1 % 3) < 2)), c2 Relations: Aggregate on (public.ft1) Remote SQL: SELECT sum(("C 1" % 3)), sum(DISTINCT ("C 1" % 3) ORDER BY (("C 1" % 3)) ASC NULLS LAST) FILTER (WHERE (("C 1" % 3) < 2)), c2 FROM "S 1"."T 1" WHERE ((c2 = 6)) GROUP BY c2 (4 rows) @@ -2718,17 +2718,17 @@ select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft QUERY PLAN ------------------------------------------------------------------------------------------------------- Unique - Output: ((SubPlan 1)) + Output: (SubPlan 1) -> Sort - Output: ((SubPlan 1)) - Sort Key: ((SubPlan 1)) + Output: (SubPlan 1) + Sort Key: (SubPlan 1) -> Foreign Scan Output: (SubPlan 1) Relations: Aggregate on (public.ft2 t2) Remote SQL: SELECT count(*) FILTER (WHERE ((c2 = 6) AND ("C 1" < 10))) FROM "S 1"."T 1" SubPlan 1 -> Foreign Scan on public.ft1 t1 - Output: (count(*) FILTER (WHERE ((t2.c2 = 6) AND (t2.c1 < 10)))) + Output: count(*) FILTER (WHERE ((t2.c2 = 6) AND (t2.c1 < 10))) Remote SQL: SELECT NULL FROM "S 1"."T 1" WHERE (("C 1" = 6)) (13 rows) @@ -2744,16 +2744,16 @@ select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) fro QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------ Unique - Output: ((SubPlan 1)) + Output: (SubPlan 1) -> Sort - Output: ((SubPlan 1)) - Sort Key: ((SubPlan 1)) + Output: (SubPlan 1) + Sort Key: (SubPlan 1) -> Foreign Scan on public.ft2 t2 Output: (SubPlan 1) Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1" SubPlan 1 -> Foreign Scan - Output: (count(t1.c1) FILTER (WHERE ((t2.c2 = 6) AND (t2.c1 < 10)))) + Output: count(t1.c1) FILTER (WHERE ((t2.c2 = 6) AND (t2.c1 < 10))) Relations: Aggregate on (public.ft1 t1) Remote SQL: SELECT count("C 1") FILTER (WHERE (($1::integer = 6) AND ($2::integer < 10))) FROM "S 1"."T 1" WHERE (("C 1" = 6)) (13 rows) @@ -2802,10 +2802,10 @@ select c2, rank('10'::varchar) within group (order by c6), percentile_cont(c2/10 QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort - Output: c2, (rank('10'::character varying) WITHIN GROUP (ORDER BY c6)), (percentile_cont((((c2)::numeric / '10'::numeric))::double precision) WITHIN GROUP (ORDER BY ((c1)::double precision))) + Output: c2, rank('10'::character varying) WITHIN GROUP (ORDER BY c6), percentile_cont((((c2)::numeric / '10'::numeric))::double precision) WITHIN GROUP (ORDER BY ((c1)::double precision)) Sort Key: ft1.c2 -> Foreign Scan - Output: c2, (rank('10'::character varying) WITHIN GROUP (ORDER BY c6)), (percentile_cont((((c2)::numeric / '10'::numeric))::double precision) WITHIN GROUP (ORDER BY ((c1)::double precision))) + Output: c2, rank('10'::character varying) WITHIN GROUP (ORDER BY c6), percentile_cont((((c2)::numeric / '10'::numeric))::double precision) WITHIN GROUP (ORDER BY ((c1)::double precision)) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c2, rank('10'::character varying) WITHIN GROUP (ORDER BY c6 ASC NULLS LAST), percentile_cont((c2 / 10::numeric)) WITHIN GROUP (ORDER BY ("C 1") ASC NULLS LAST) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2 HAVING ((percentile_cont((c2 / 10::numeric)) WITHIN GROUP (ORDER BY ("C 1") ASC NULLS LAST) < 500::double precision)) (7 rows) @@ -2826,7 +2826,7 @@ select c1, rank(c1, c2) within group (order by c1, c2) from ft1 group by c1, c2 QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: c1, (rank(c1, c2) WITHIN GROUP (ORDER BY c1, c2)), c2 + Output: c1, rank(c1, c2) WITHIN GROUP (ORDER BY c1, c2), c2 Relations: Aggregate on (public.ft1) Remote SQL: SELECT "C 1", rank("C 1", c2) WITHIN GROUP (ORDER BY "C 1" ASC NULLS LAST, c2 ASC NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" = 6)) GROUP BY "C 1", c2 (4 rows) @@ -2870,10 +2870,10 @@ select c2, least_agg(c1) from ft1 where c2 < 100 group by c2 order by c2; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------ Sort - Output: c2, (least_agg(VARIADIC ARRAY[c1])) + Output: c2, least_agg(VARIADIC ARRAY[c1]) Sort Key: ft1.c2 -> Foreign Scan - Output: c2, (least_agg(VARIADIC ARRAY[c1])) + Output: c2, least_agg(VARIADIC ARRAY[c1]) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c2, public.least_agg(VARIADIC ARRAY["C 1"]) FROM "S 1"."T 1" WHERE ((c2 < 100)) GROUP BY c2 (7 rows) @@ -2972,7 +2972,7 @@ select array_agg(c1 order by c1 using operator(public.<^)) from ft2 where c2 = 6 QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------- Foreign Scan - Output: (array_agg(c1 ORDER BY c1 USING <^ NULLS LAST)), c2 + Output: array_agg(c1 ORDER BY c1 USING <^ NULLS LAST), c2 Relations: Aggregate on (public.ft2) Remote SQL: SELECT array_agg("C 1" ORDER BY "C 1" USING OPERATOR(public.<^) NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" < 100)) AND ((c2 = 6)) GROUP BY c2 (4 rows) @@ -3052,7 +3052,7 @@ select count(*), x.b from ft1, (select c2 a, sum(c1) b from ft1 group by c2) x w -> Subquery Scan on x Output: x.b, x.a -> Foreign Scan - Output: ft1_1.c2, (sum(ft1_1.c1)) + Output: ft1_1.c2, sum(ft1_1.c1) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c2, sum("C 1") FROM "S 1"."T 1" GROUP BY c2 (20 rows) @@ -3078,10 +3078,10 @@ select avg(t1.c1), sum(t2.c1) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) gr QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort - Output: (avg(t1.c1)), (sum(t2.c1)), t2.c1 - Sort Key: (avg(t1.c1)), (sum(t2.c1)) + Output: avg(t1.c1), sum(t2.c1), t2.c1 + Sort Key: avg(t1.c1), sum(t2.c1) -> Foreign Scan - Output: (avg(t1.c1)), (sum(t2.c1)), t2.c1 + Output: avg(t1.c1), sum(t2.c1), t2.c1 Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2)) Remote SQL: SELECT avg(r1.c1), sum(r2.c1), r2.c1 FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) GROUP BY r2.c1 HAVING ((((avg(r1.c1) IS NULL) AND (sum(r2.c1) < 10)) OR (sum(r2.c1) IS NULL))) (7 rows) @@ -3098,13 +3098,13 @@ select avg(t1.c1), sum(t2.c1) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) gr -- foreign server. explain (verbose, costs off) select sum(c2) * (random() <= 1)::int as sum from ft1 order by 1; - QUERY PLAN --------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------- Sort - Output: (((sum(c2)) * ((random() <= '1'::double precision))::integer)) - Sort Key: (((sum(ft1.c2)) * ((random() <= '1'::double precision))::integer)) + Output: (sum(c2) * ((random() <= '1'::double precision))::integer) + Sort Key: (sum(ft1.c2) * ((random() <= '1'::double precision))::integer) -> Foreign Scan - Output: ((sum(c2)) * ((random() <= '1'::double precision))::integer) + Output: (sum(c2) * ((random() <= '1'::double precision))::integer) Relations: Aggregate on (public.ft1) Remote SQL: SELECT sum(c2) FROM "S 1"."T 1" (7 rows) @@ -3133,7 +3133,7 @@ select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum fr Output: qry.sum, t2.c1 Filter: ((t1.c2 * 2) = qry.sum) -> Foreign Scan - Output: (sum((t2.c1 + t1."C 1"))), t2.c1 + Output: sum((t2.c1 + t1."C 1")), t2.c1 Relations: Aggregate on (public.ft2 t2) Remote SQL: SELECT sum(("C 1" + $1::integer)), "C 1" FROM "S 1"."T 1" GROUP BY "C 1" (15 rows) @@ -3178,7 +3178,7 @@ select q.b, count(ft4.c1), sum(q.a) from ft4 left join (select min(13), avg(ft1. -> Subquery Scan on q Output: q.b, q.a -> Foreign Scan - Output: (min(13)), (avg(ft1.c1)), (NULL::bigint) + Output: min(13), avg(ft1.c1), NULL::bigint Relations: Aggregate on ((public.ft1) INNER JOIN (public.ft2)) Remote SQL: SELECT min(13), avg(r1."C 1"), NULL::bigint FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r2."C 1" = 12)) AND ((r1."C 1" = 12)))) (23 rows) @@ -3293,12 +3293,12 @@ select distinct sum(c1)/1000 s from ft2 where c2 < 6 group by c2 order by 1; QUERY PLAN -------------------------------------------------------------------------------------------------------- Unique - Output: ((sum(c1) / 1000)), c2 + Output: (sum(c1) / 1000), c2 -> Sort - Output: ((sum(c1) / 1000)), c2 - Sort Key: ((sum(ft2.c1) / 1000)) + Output: (sum(c1) / 1000), c2 + Sort Key: (sum(ft2.c1) / 1000) -> Foreign Scan - Output: ((sum(c1) / 1000)), c2 + Output: (sum(c1) / 1000), c2 Relations: Aggregate on (public.ft2) Remote SQL: SELECT (sum("C 1") / 1000), c2 FROM "S 1"."T 1" WHERE ((c2 < 6)) GROUP BY c2 (9 rows) @@ -3316,15 +3316,15 @@ select c2, sum(c2), count(c2) over (partition by c2%2) from ft2 where c2 < 10 gr QUERY PLAN ------------------------------------------------------------------------------------------------------------- Sort - Output: c2, (sum(c2)), (count(c2) OVER (?)), ((c2 % 2)) + Output: c2, sum(c2), (count(c2) OVER (?)), (c2 % 2) Sort Key: ft2.c2 -> WindowAgg - Output: c2, (sum(c2)), count(c2) OVER (?), ((c2 % 2)) + Output: c2, sum(c2), count(c2) OVER (?), (c2 % 2) -> Sort - Output: c2, ((c2 % 2)), (sum(c2)) - Sort Key: ((ft2.c2 % 2)) + Output: c2, (c2 % 2), sum(c2) + Sort Key: (ft2.c2 % 2) -> Foreign Scan - Output: c2, ((c2 % 2)), (sum(c2)) + Output: c2, (c2 % 2), sum(c2) Relations: Aggregate on (public.ft2) Remote SQL: SELECT c2, (c2 % 2), sum(c2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2 (12 rows) @@ -3349,15 +3349,15 @@ select c2, array_agg(c2) over (partition by c2%2 order by c2 desc) from ft1 wher QUERY PLAN ---------------------------------------------------------------------------------------------------- Sort - Output: c2, (array_agg(c2) OVER (?)), ((c2 % 2)) + Output: c2, (array_agg(c2) OVER (?)), (c2 % 2) Sort Key: ft1.c2 -> WindowAgg - Output: c2, array_agg(c2) OVER (?), ((c2 % 2)) + Output: c2, array_agg(c2) OVER (?), (c2 % 2) -> Sort - Output: c2, ((c2 % 2)) - Sort Key: ((ft1.c2 % 2)), ft1.c2 DESC + Output: c2, (c2 % 2) + Sort Key: (ft1.c2 % 2), ft1.c2 DESC -> Foreign Scan - Output: c2, ((c2 % 2)) + Output: c2, (c2 % 2) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c2, (c2 % 2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2 (12 rows) @@ -3382,15 +3382,15 @@ select c2, array_agg(c2) over (partition by c2%2 order by c2 range between curre QUERY PLAN ---------------------------------------------------------------------------------------------------- Sort - Output: c2, (array_agg(c2) OVER (?)), ((c2 % 2)) + Output: c2, (array_agg(c2) OVER (?)), (c2 % 2) Sort Key: ft1.c2 -> WindowAgg - Output: c2, array_agg(c2) OVER (?), ((c2 % 2)) + Output: c2, array_agg(c2) OVER (?), (c2 % 2) -> Sort - Output: c2, ((c2 % 2)) - Sort Key: ((ft1.c2 % 2)), ft1.c2 + Output: c2, (c2 % 2) + Sort Key: (ft1.c2 % 2), ft1.c2 -> Foreign Scan - Output: c2, ((c2 % 2)) + Output: c2, (c2 % 2) Relations: Aggregate on (public.ft1) Remote SQL: SELECT c2, (c2 % 2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2 (12 rows) @@ -3645,7 +3645,7 @@ SELECT tableoid::regclass, * FROM ft1 t1 LIMIT 1; QUERY PLAN ------------------------------------------------------------------------------- Limit - Output: ((tableoid)::regclass), c1, c2, c3, c4, c5, c6, c7, c8 + Output: (tableoid)::regclass, c1, c2, c3, c4, c5, c6, c7, c8 -> Foreign Scan on public.ft1 t1 Output: (tableoid)::regclass, c1, c2, c3, c4, c5, c6, c7, c8 Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" @@ -3901,7 +3901,7 @@ INSERT INTO ft2 (c1,c2,c3) SELECT c1+1000,c2+100, c3 || c3 FROM ft2 LIMIT 20; -> Subquery Scan on "*SELECT*" Output: "*SELECT*"."?column?", "*SELECT*"."?column?_1", NULL::integer, "*SELECT*"."?column?_2", NULL::timestamp with time zone, NULL::timestamp without time zone, NULL::character varying, 'ft2 '::character(10), NULL::user_enum -> Limit - Output: ((ft2_1.c1 + 1000)), ((ft2_1.c2 + 100)), ((ft2_1.c3 || ft2_1.c3)) + Output: (ft2_1.c1 + 1000), (ft2_1.c2 + 100), (ft2_1.c3 || ft2_1.c3) -> Foreign Scan on public.ft2 ft2_1 Output: (ft2_1.c1 + 1000), (ft2_1.c2 + 100), (ft2_1.c3 || ft2_1.c3) Remote SQL: SELECT "C 1", c2, c3 FROM "S 1"."T 1" @@ -5575,7 +5575,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 < 0; QUERY PLAN ----------------------------------------------------------------- Foreign Scan - Output: (count(*)) + Output: count(*) Relations: Aggregate on (public.ft1) Remote SQL: SELECT count(*) FROM "S 1"."T 1" WHERE ((c2 < 0)) (4 rows) @@ -5619,7 +5619,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 >= 0; QUERY PLAN ------------------------------------------------------------------ Foreign Scan - Output: (count(*)) + Output: count(*) Relations: Aggregate on (public.ft1) Remote SQL: SELECT count(*) FROM "S 1"."T 1" WHERE ((c2 >= 0)) (4 rows) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 8a81d7a..8628b18 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -6037,7 +6037,7 @@ get_variable(Var *var, int levelsup, bool istoplevel, deparse_context *context) } else { - resolve_special_varno((Node *) var, context, NULL, + resolve_special_varno((Node *) var, context, dpns, get_special_variable); return NULL; } @@ -6168,15 +6168,17 @@ static void get_special_variable(Node *node, deparse_context *context, void *private) { StringInfo buf = context->buf; + deparse_namespace *dpns = (deparse_namespace *) private; /* * Force parentheses because our caller probably assumed a Var is a simple - * expression. + * expression. However if underneath PlanState is ForeignScanState, then + * don't force parentheses. */ - if (!IsA(node, Var)) + if (!IsA(node, Var) && !IsA(dpns->planstate, ForeignScanState)) appendStringInfoChar(buf, '('); get_rule_expr(node, context, true); - if (!IsA(node, Var)) + if (!IsA(node, Var) && !IsA(dpns->planstate, ForeignScanState)) appendStringInfoChar(buf, ')'); }