@@ -1751,16 +1751,15 @@ explain (analyze, costs off, summary off, timing off) execute ab_q3 (2, 2);
17511751-- Suppress the number of loops each parallel node runs for. This is because
17521752-- more than one worker may run the same parallel node if timing conditions
17531753-- 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
17551755language plpgsql as
17561756$$
17571757declare
17581758 ln text;
1759- args text := string_agg(u::text, ', ') from unnest($2) u;
17601759begin
17611760 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)
17641763 loop
17651764 if ln like '%Parallel%' then
17661765 ln := regexp_replace(ln, 'loops=\d*', 'loops=N');
@@ -1808,7 +1807,7 @@ execute ab_q4 (1, 8);
18081807
18091808(1 row)
18101809
1811- select explain_parallel_append('ab_q4', '{ 2, 2} ');
1810+ select explain_parallel_append('execute ab_q4 ( 2, 2) ');
18121811 explain_parallel_append
18131812-------------------------------------------------------------------------------
18141813 Finalize Aggregate (actual rows=1 loops=1)
@@ -1861,7 +1860,7 @@ execute ab_q5 (1, 2, 3);
18611860
18621861(1 row)
18631862
1864- select explain_parallel_append('ab_q5', '{ 1, 1, 1} ');
1863+ select explain_parallel_append('execute ab_q5 ( 1, 1, 1) ');
18651864 explain_parallel_append
18661865-------------------------------------------------------------------------------
18671866 Finalize Aggregate (actual rows=1 loops=1)
@@ -1879,7 +1878,7 @@ select explain_parallel_append('ab_q5', '{1, 1, 1}');
18791878 Filter: ((b < 4) AND (a = ANY (ARRAY[$1, $2, $3])))
18801879(13 rows)
18811880
1882- select explain_parallel_append('ab_q5', '{ 2, 3, 3} ');
1881+ select explain_parallel_append('execute ab_q5 ( 2, 3, 3) ');
18831882 explain_parallel_append
18841883-------------------------------------------------------------------------------
18851884 Finalize Aggregate (actual rows=1 loops=1)
@@ -1905,7 +1904,7 @@ select explain_parallel_append('ab_q5', '{2, 3, 3}');
19051904
19061905-- Try some params whose values do not belong to any partition.
19071906-- 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) ');
19091908 explain_parallel_append
19101909-------------------------------------------------------------------------------
19111910 Finalize Aggregate (actual rows=1 loops=1)
@@ -1919,7 +1918,29 @@ select explain_parallel_append('ab_q5', '{33, 44, 55}');
19191918 Filter: ((b < 4) AND (a = ANY (ARRAY[$1, $2, $3])))
19201919(9 rows)
19211920
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
19231944create table lprt_a (a int not null);
19241945-- Insert some values we won't find in ab
19251946insert 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);
19371958create index ab_a3_b3_a_idx on ab_a3_b3 (a);
19381959set enable_hashjoin = 0;
19391960set 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)');
19731962 explain_parallel_append
19741963---------------------------------------------------------------------------------------------------
19751964 Finalize Aggregate (actual rows=1 loops=1)
@@ -2002,16 +1991,16 @@ select explain_parallel_append('ab_q6', '{0, 0, 1}');
20021991(27 rows)
20031992
20041993insert 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
20071996---------------------------------------------------------------------------------------------------
20081997 Finalize Aggregate (actual rows=1 loops=1)
20091998 -> Gather (actual rows=2 loops=1)
20101999 Workers Planned: 1
20112000 Workers Launched: 1
20122001 -> Partial Aggregate (actual rows=1 loops=2)
20132002 -> 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 )
20152004 Filter: (a = ANY ('{1,0,3}'::integer[]))
20162005 -> Append (actual rows=0 loops=104)
20172006 -> 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);
20342023 Index Cond: (a = a.a)
20352024(27 rows)
20362025
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
20392028---------------------------------------------------------------------------------------------------
20402029 Finalize Aggregate (actual rows=1 loops=1)
20412030 -> Gather (actual rows=2 loops=1)
20422031 Workers Planned: 1
20432032 Workers Launched: 1
20442033 -> Partial Aggregate (actual rows=1 loops=2)
20452034 -> 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 )
20472036 Filter: (a = ANY ('{1,0,0}'::integer[]))
20482037 Rows Removed by Filter: 1
20492038 -> Append (actual rows=0 loops=102)
@@ -2068,16 +2057,16 @@ explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 0);
20682057(28 rows)
20692058
20702059delete 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
20732062--------------------------------------------------------------------------------------------
20742063 Finalize Aggregate (actual rows=1 loops=1)
20752064 -> Gather (actual rows=2 loops=1)
20762065 Workers Planned: 1
20772066 Workers Launched: 1
20782067 -> Partial Aggregate (actual rows=1 loops=2)
20792068 -> 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 )
20812070 Filter: (a = ANY ('{1,0,0}'::integer[]))
20822071 Rows Removed by Filter: 1
20832072 -> Append (actual rows=0 loops=100)
@@ -2171,7 +2160,6 @@ deallocate ab_q2;
21712160deallocate ab_q3;
21722161deallocate ab_q4;
21732162deallocate ab_q5;
2174- deallocate ab_q6;
21752163drop table ab, lprt_a;
21762164-- Join
21772165create table tbl1(col1 int);
0 commit comments