@@ -1751,16 +1751,15 @@ explain (analyze, costs off, summary off, timing off) execute ab_q3 (2, 2);
1751
1751
-- Suppress the number of loops each parallel node runs for. This is because
1752
1752
-- more than one worker may run the same parallel node if timing conditions
1753
1753
-- are just right, which destabilizes the test.
1754
- create function explain_parallel_append(text, int[] ) returns setof text
1754
+ create function explain_parallel_append(text) returns setof text
1755
1755
language plpgsql as
1756
1756
$$
1757
1757
declare
1758
1758
ln text;
1759
- args text := string_agg(u::text, ', ') from unnest($2) u;
1760
1759
begin
1761
1760
for ln in
1762
- execute format('explain (analyze, costs off, summary off, timing off) execute %s(%s) ',
1763
- $1, args )
1761
+ execute format('explain (analyze, costs off, summary off, timing off) %s ',
1762
+ $1)
1764
1763
loop
1765
1764
if ln like '%Parallel%' then
1766
1765
ln := regexp_replace(ln, 'loops=\d*', 'loops=N');
@@ -1808,7 +1807,7 @@ execute ab_q4 (1, 8);
1808
1807
1809
1808
(1 row)
1810
1809
1811
- select explain_parallel_append('ab_q4', '{ 2, 2} ');
1810
+ select explain_parallel_append('execute ab_q4 ( 2, 2) ');
1812
1811
explain_parallel_append
1813
1812
-------------------------------------------------------------------------------
1814
1813
Finalize Aggregate (actual rows=1 loops=1)
@@ -1861,7 +1860,7 @@ execute ab_q5 (1, 2, 3);
1861
1860
1862
1861
(1 row)
1863
1862
1864
- select explain_parallel_append('ab_q5', '{ 1, 1, 1} ');
1863
+ select explain_parallel_append('execute ab_q5 ( 1, 1, 1) ');
1865
1864
explain_parallel_append
1866
1865
-------------------------------------------------------------------------------
1867
1866
Finalize Aggregate (actual rows=1 loops=1)
@@ -1879,7 +1878,7 @@ select explain_parallel_append('ab_q5', '{1, 1, 1}');
1879
1878
Filter: ((b < 4) AND (a = ANY (ARRAY[$1, $2, $3])))
1880
1879
(13 rows)
1881
1880
1882
- select explain_parallel_append('ab_q5', '{ 2, 3, 3} ');
1881
+ select explain_parallel_append('execute ab_q5 ( 2, 3, 3) ');
1883
1882
explain_parallel_append
1884
1883
-------------------------------------------------------------------------------
1885
1884
Finalize Aggregate (actual rows=1 loops=1)
@@ -1905,7 +1904,7 @@ select explain_parallel_append('ab_q5', '{2, 3, 3}');
1905
1904
1906
1905
-- Try some params whose values do not belong to any partition.
1907
1906
-- We'll still get a single subplan in this case, but it should not be scanned.
1908
- select explain_parallel_append('ab_q5', '{ 33, 44, 55} ');
1907
+ select explain_parallel_append('execute ab_q5 ( 33, 44, 55) ');
1909
1908
explain_parallel_append
1910
1909
-------------------------------------------------------------------------------
1911
1910
Finalize Aggregate (actual rows=1 loops=1)
@@ -1919,7 +1918,29 @@ select explain_parallel_append('ab_q5', '{33, 44, 55}');
1919
1918
Filter: ((b < 4) AND (a = ANY (ARRAY[$1, $2, $3])))
1920
1919
(9 rows)
1921
1920
1922
- -- Test parallel Append with IN list and parameterized nested loops
1921
+ -- Test Parallel Append with exec params
1922
+ select explain_parallel_append('select count(*) from ab where (a = (select 1) or a = (select 3)) and b = 2');
1923
+ explain_parallel_append
1924
+ -------------------------------------------------------------------------
1925
+ Aggregate (actual rows=1 loops=1)
1926
+ InitPlan 1 (returns $0)
1927
+ -> Result (actual rows=1 loops=1)
1928
+ InitPlan 2 (returns $1)
1929
+ -> Result (actual rows=1 loops=1)
1930
+ -> Gather (actual rows=0 loops=1)
1931
+ Workers Planned: 2
1932
+ Params Evaluated: $0, $1
1933
+ Workers Launched: 2
1934
+ -> Parallel Append (actual rows=0 loops=N)
1935
+ -> Parallel Seq Scan on ab_a1_b2 (actual rows=0 loops=N)
1936
+ Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
1937
+ -> Parallel Seq Scan on ab_a2_b2 (never executed)
1938
+ Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
1939
+ -> Parallel Seq Scan on ab_a3_b2 (actual rows=0 loops=N)
1940
+ Filter: ((b = 2) AND ((a = $0) OR (a = $1)))
1941
+ (16 rows)
1942
+
1943
+ -- Test pruning during parallel nested loop query
1923
1944
create table lprt_a (a int not null);
1924
1945
-- Insert some values we won't find in ab
1925
1946
insert into lprt_a select 0 from generate_series(1,100);
@@ -1937,39 +1958,7 @@ create index ab_a3_b2_a_idx on ab_a3_b2 (a);
1937
1958
create index ab_a3_b3_a_idx on ab_a3_b3 (a);
1938
1959
set enable_hashjoin = 0;
1939
1960
set enable_mergejoin = 0;
1940
- prepare ab_q6 (int, int, int) as
1941
- select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in($1,$2,$3);
1942
- execute ab_q6 (1, 2, 3);
1943
- avg
1944
- -----
1945
-
1946
- (1 row)
1947
-
1948
- execute ab_q6 (1, 2, 3);
1949
- avg
1950
- -----
1951
-
1952
- (1 row)
1953
-
1954
- execute ab_q6 (1, 2, 3);
1955
- avg
1956
- -----
1957
-
1958
- (1 row)
1959
-
1960
- execute ab_q6 (1, 2, 3);
1961
- avg
1962
- -----
1963
-
1964
- (1 row)
1965
-
1966
- execute ab_q6 (1, 2, 3);
1967
- avg
1968
- -----
1969
-
1970
- (1 row)
1971
-
1972
- select explain_parallel_append('ab_q6', '{0, 0, 1}');
1961
+ select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in(0, 0, 1)');
1973
1962
explain_parallel_append
1974
1963
---------------------------------------------------------------------------------------------------
1975
1964
Finalize Aggregate (actual rows=1 loops=1)
@@ -2002,16 +1991,16 @@ select explain_parallel_append('ab_q6', '{0, 0, 1}');
2002
1991
(27 rows)
2003
1992
2004
1993
insert into lprt_a values(3),(3);
2005
- explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 3);
2006
- QUERY PLAN
1994
+ select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in (1, 0, 3)' );
1995
+ explain_parallel_append
2007
1996
---------------------------------------------------------------------------------------------------
2008
1997
Finalize Aggregate (actual rows=1 loops=1)
2009
1998
-> Gather (actual rows=2 loops=1)
2010
1999
Workers Planned: 1
2011
2000
Workers Launched: 1
2012
2001
-> Partial Aggregate (actual rows=1 loops=2)
2013
2002
-> Nested Loop (actual rows=0 loops=2)
2014
- -> Parallel Seq Scan on lprt_a a (actual rows=52 loops=2 )
2003
+ -> Parallel Seq Scan on lprt_a a (actual rows=52 loops=N )
2015
2004
Filter: (a = ANY ('{1,0,3}'::integer[]))
2016
2005
-> Append (actual rows=0 loops=104)
2017
2006
-> Index Scan using ab_a1_b1_a_idx on ab_a1_b1 (actual rows=0 loops=2)
@@ -2034,16 +2023,16 @@ explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 3);
2034
2023
Index Cond: (a = a.a)
2035
2024
(27 rows)
2036
2025
2037
- explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 0);
2038
- QUERY PLAN
2026
+ select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in (1, 0, 0)' );
2027
+ explain_parallel_append
2039
2028
---------------------------------------------------------------------------------------------------
2040
2029
Finalize Aggregate (actual rows=1 loops=1)
2041
2030
-> Gather (actual rows=2 loops=1)
2042
2031
Workers Planned: 1
2043
2032
Workers Launched: 1
2044
2033
-> Partial Aggregate (actual rows=1 loops=2)
2045
2034
-> Nested Loop (actual rows=0 loops=2)
2046
- -> Parallel Seq Scan on lprt_a a (actual rows=51 loops=2 )
2035
+ -> Parallel Seq Scan on lprt_a a (actual rows=51 loops=N )
2047
2036
Filter: (a = ANY ('{1,0,0}'::integer[]))
2048
2037
Rows Removed by Filter: 1
2049
2038
-> Append (actual rows=0 loops=102)
@@ -2068,16 +2057,16 @@ explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 0);
2068
2057
(28 rows)
2069
2058
2070
2059
delete from lprt_a where a = 1;
2071
- explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 0);
2072
- QUERY PLAN
2060
+ select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in (1, 0, 0)' );
2061
+ explain_parallel_append
2073
2062
--------------------------------------------------------------------------------------------
2074
2063
Finalize Aggregate (actual rows=1 loops=1)
2075
2064
-> Gather (actual rows=2 loops=1)
2076
2065
Workers Planned: 1
2077
2066
Workers Launched: 1
2078
2067
-> Partial Aggregate (actual rows=1 loops=2)
2079
2068
-> Nested Loop (actual rows=0 loops=2)
2080
- -> Parallel Seq Scan on lprt_a a (actual rows=50 loops=2 )
2069
+ -> Parallel Seq Scan on lprt_a a (actual rows=50 loops=N )
2081
2070
Filter: (a = ANY ('{1,0,0}'::integer[]))
2082
2071
Rows Removed by Filter: 1
2083
2072
-> Append (actual rows=0 loops=100)
@@ -2171,7 +2160,6 @@ deallocate ab_q2;
2171
2160
deallocate ab_q3;
2172
2161
deallocate ab_q4;
2173
2162
deallocate ab_q5;
2174
- deallocate ab_q6;
2175
2163
drop table ab, lprt_a;
2176
2164
-- Join
2177
2165
create table tbl1(col1 int);
0 commit comments