Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa7f593

Browse files
committed
Improve speed of contrib/postgres_fdw regression tests.
Commit 7012b13 added some tests that consumed an excessive amount of time, more than tripling the time needed for "make installcheck" for this module. Add filter conditions to reduce the number of rows scanned, bringing the runtime down to within hailing distance of what it was before. Jeevan Chalke and Ashutosh Bapat, per a gripe from me Discussion: https://postgr.es/m/16565.1478104765@sss.pgh.pa.us
1 parent 3838074 commit aa7f593

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

+15-21
Original file line numberDiff line numberDiff line change
@@ -2685,9 +2685,9 @@ select sum(c1%3), sum(distinct c1%3 order by c1%3) filter (where c1%3 < 2), c2 f
26852685

26862686
-- Outer query is aggregation query
26872687
explain (verbose, costs off)
2688-
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
2689-
QUERY PLAN
2690-
-------------------------------------------------------------------------------------------------------
2688+
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
2689+
QUERY PLAN
2690+
------------------------------------------------------------------------------------------------------------------------------
26912691
Unique
26922692
Output: ((SubPlan 1))
26932693
-> Sort
@@ -2696,22 +2696,22 @@ select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft
26962696
-> Foreign Scan
26972697
Output: (SubPlan 1)
26982698
Relations: Aggregate on (public.ft2 t2)
2699-
Remote SQL: SELECT count(*) FILTER (WHERE ((c2 = 6) AND ("C 1" < 10))) FROM "S 1"."T 1"
2699+
Remote SQL: SELECT count(*) FILTER (WHERE ((c2 = 6) AND ("C 1" < 10))) FROM "S 1"."T 1" WHERE (((c2 % 6) = 0))
27002700
SubPlan 1
27012701
-> Foreign Scan on public.ft1 t1
27022702
Output: (count(*) FILTER (WHERE ((t2.c2 = 6) AND (t2.c1 < 10))))
27032703
Remote SQL: SELECT NULL FROM "S 1"."T 1" WHERE (("C 1" = 6))
27042704
(13 rows)
27052705

2706-
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
2706+
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
27072707
count
27082708
-------
27092709
1
27102710
(1 row)
27112711

27122712
-- Inner query is aggregation query
27132713
explain (verbose, costs off)
2714-
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
2714+
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
27152715
QUERY PLAN
27162716
------------------------------------------------------------------------------------------------------------------------------------------------------
27172717
Unique
@@ -2721,15 +2721,15 @@ select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) fro
27212721
Sort Key: ((SubPlan 1))
27222722
-> Foreign Scan on public.ft2 t2
27232723
Output: (SubPlan 1)
2724-
Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1"
2724+
Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1" WHERE (((c2 % 6) = 0))
27252725
SubPlan 1
27262726
-> Foreign Scan
27272727
Output: (count(t1.c1) FILTER (WHERE ((t2.c2 = 6) AND (t2.c1 < 10))))
27282728
Relations: Aggregate on (public.ft1 t1)
27292729
Remote SQL: SELECT count("C 1") FILTER (WHERE (($1::integer = 6) AND ($2::integer < 10))) FROM "S 1"."T 1" WHERE (("C 1" = 6))
27302730
(13 rows)
27312731

2732-
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
2732+
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
27332733
count
27342734
-------
27352735
0
@@ -3086,39 +3086,33 @@ select sum(c2) * (random() <= 1)::int as sum from ft1 order by 1;
30863086
-- LATERAL join, with parameterization
30873087
set enable_hashagg to false;
30883088
explain (verbose, costs off)
3089-
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 10 order by 1;
3089+
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 3 and t1."C 1" < 100 order by 1;
30903090
QUERY PLAN
30913091
----------------------------------------------------------------------------------------------------------
30923092
Sort
30933093
Output: t1.c2, qry.sum
30943094
Sort Key: t1.c2
30953095
-> Nested Loop
30963096
Output: t1.c2, qry.sum
3097-
-> Seq Scan on "S 1"."T 1" t1
3097+
-> Index Scan using t1_pkey on "S 1"."T 1" t1
30983098
Output: t1."C 1", t1.c2, t1.c3, t1.c4, t1.c5, t1.c6, t1.c7, t1.c8
3099-
Filter: (t1.c2 < 10)
3099+
Index Cond: (t1."C 1" < 100)
3100+
Filter: (t1.c2 < 3)
31003101
-> Subquery Scan on qry
31013102
Output: qry.sum, t2.c1
31023103
Filter: ((t1.c2 * 2) = qry.sum)
31033104
-> Foreign Scan
31043105
Output: (sum((t2.c1 + t1."C 1"))), t2.c1
31053106
Relations: Aggregate on (public.ft2 t2)
31063107
Remote SQL: SELECT sum(("C 1" + $1::integer)), "C 1" FROM "S 1"."T 1" GROUP BY "C 1"
3107-
(15 rows)
3108+
(16 rows)
31083109

3109-
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 10 order by 1;
3110+
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 3 and t1."C 1" < 100 order by 1;
31103111
c2 | sum
31113112
----+-----
31123113
1 | 2
31133114
2 | 4
3114-
3 | 6
3115-
4 | 8
3116-
5 | 10
3117-
6 | 12
3118-
7 | 14
3119-
8 | 16
3120-
9 | 18
3121-
(9 rows)
3115+
(2 rows)
31223116

31233117
reset enable_hashagg;
31243118
-- Check with placeHolderVars

contrib/postgres_fdw/sql/postgres_fdw.sql

+6-6
Original file line numberDiff line numberDiff line change
@@ -641,12 +641,12 @@ select sum(c1%3), sum(distinct c1%3 order by c1%3) filter (where c1%3 < 2), c2 f
641641

642642
-- Outer query is aggregation query
643643
explain (verbose, costs off)
644-
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
645-
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
644+
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
645+
select distinct (select count(*) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
646646
-- Inner query is aggregation query
647647
explain (verbose, costs off)
648-
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
649-
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 order by 1;
648+
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
649+
select distinct (select count(t1.c1) filter (where t2.c2 = 6 and t2.c1 < 10) from ft1 t1 where t1.c1 = 6) from ft2 t2 where t2.c2 % 6 = 0 order by 1;
650650

651651
-- Aggregate not pushed down as FILTER condition is not pushable
652652
explain (verbose, costs off)
@@ -802,8 +802,8 @@ select sum(c2) * (random() <= 1)::int as sum from ft1 order by 1;
802802
-- LATERAL join, with parameterization
803803
set enable_hashagg to false;
804804
explain (verbose, costs off)
805-
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 10 order by 1;
806-
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 10 order by 1;
805+
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 3 and t1."C 1" < 100 order by 1;
806+
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 3 and t1."C 1" < 100 order by 1;
807807
reset enable_hashagg;
808808

809809
-- Check with placeHolderVars

0 commit comments

Comments
 (0)