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

Commit 95cdc77

Browse files
committed
Improve coverage of nodeAppend runtime partition prune
coverage report indicated that mark_invalid_subplans_as_finished() and nearby code was not getting exercised by any tests. Add a new one which has execution-time Params rather than only external Params to fix this. In passing, David noticed that ab_q6 tests were not actually required to have a generic plan. The tests were testing exec Params not external Params, so there was no need for the PREPARE. Remove the PREPARE, making these plain queries. (The new queries are called from explain_parallel_append, which may be unnecessary since they don't actually have a Parallel Append node, just an Append. But it doesn't seem to hurt anything, either.) Author: David Rowley Discussion: https://postgr.es/m/CAKJS1f--hopb6JBSDY4wiXTS3ZcDp-wparXjTQ1nzNdBa04Fog@mail.gmail.com
1 parent 0303051 commit 95cdc77

File tree

2 files changed

+55
-74
lines changed

2 files changed

+55
-74
lines changed

src/test/regress/expected/partition_prune.out

+40-52
Original file line numberDiff line numberDiff line change
@@ -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
17551755
language plpgsql as
17561756
$$
17571757
declare
17581758
ln text;
1759-
args text := string_agg(u::text, ', ') from unnest($2) u;
17601759
begin
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
19231944
create table lprt_a (a int not null);
19241945
-- Insert some values we won't find in ab
19251946
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);
19371958
create index ab_a3_b3_a_idx on ab_a3_b3 (a);
19381959
set enable_hashjoin = 0;
19391960
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)');
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

20041993
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
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

20702059
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
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;
21712160
deallocate ab_q3;
21722161
deallocate ab_q4;
21732162
deallocate ab_q5;
2174-
deallocate ab_q6;
21752163
drop table ab, lprt_a;
21762164
-- Join
21772165
create table tbl1(col1 int);

src/test/regress/sql/partition_prune.sql

+15-22
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,15 @@ explain (analyze, costs off, summary off, timing off) execute ab_q3 (2, 2);
364364
-- Suppress the number of loops each parallel node runs for. This is because
365365
-- more than one worker may run the same parallel node if timing conditions
366366
-- are just right, which destabilizes the test.
367-
create function explain_parallel_append(text, int[]) returns setof text
367+
create function explain_parallel_append(text) returns setof text
368368
language plpgsql as
369369
$$
370370
declare
371371
ln text;
372-
args text := string_agg(u::text, ', ') from unnest($2) u;
373372
begin
374373
for ln in
375-
execute format('explain (analyze, costs off, summary off, timing off) execute %s(%s)',
376-
$1, args)
374+
execute format('explain (analyze, costs off, summary off, timing off) %s',
375+
$1)
377376
loop
378377
if ln like '%Parallel%' then
379378
ln := regexp_replace(ln, 'loops=\d*', 'loops=N');
@@ -399,7 +398,7 @@ execute ab_q4 (1, 8);
399398
execute ab_q4 (1, 8);
400399
execute ab_q4 (1, 8);
401400
execute ab_q4 (1, 8);
402-
select explain_parallel_append('ab_q4', '{2, 2}');
401+
select explain_parallel_append('execute ab_q4 (2, 2)');
403402

404403
-- Test run-time pruning with IN lists.
405404
prepare ab_q5 (int, int, int) as
@@ -413,14 +412,17 @@ execute ab_q5 (1, 2, 3);
413412
execute ab_q5 (1, 2, 3);
414413
execute ab_q5 (1, 2, 3);
415414

416-
select explain_parallel_append('ab_q5', '{1, 1, 1}');
417-
select explain_parallel_append('ab_q5', '{2, 3, 3}');
415+
select explain_parallel_append('execute ab_q5 (1, 1, 1)');
416+
select explain_parallel_append('execute ab_q5 (2, 3, 3)');
418417

419418
-- Try some params whose values do not belong to any partition.
420419
-- We'll still get a single subplan in this case, but it should not be scanned.
421-
select explain_parallel_append('ab_q5', '{33, 44, 55}');
420+
select explain_parallel_append('execute ab_q5 (33, 44, 55)');
422421

423-
-- Test parallel Append with IN list and parameterized nested loops
422+
-- Test Parallel Append with exec params
423+
select explain_parallel_append('select count(*) from ab where (a = (select 1) or a = (select 3)) and b = 2');
424+
425+
-- Test pruning during parallel nested loop query
424426
create table lprt_a (a int not null);
425427
-- Insert some values we won't find in ab
426428
insert into lprt_a select 0 from generate_series(1,100);
@@ -443,24 +445,16 @@ create index ab_a3_b3_a_idx on ab_a3_b3 (a);
443445
set enable_hashjoin = 0;
444446
set enable_mergejoin = 0;
445447

446-
prepare ab_q6 (int, int, int) as
447-
select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in($1,$2,$3);
448-
execute ab_q6 (1, 2, 3);
449-
execute ab_q6 (1, 2, 3);
450-
execute ab_q6 (1, 2, 3);
451-
execute ab_q6 (1, 2, 3);
452-
execute ab_q6 (1, 2, 3);
453-
454-
select explain_parallel_append('ab_q6', '{0, 0, 1}');
448+
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)');
455449

456450
insert into lprt_a values(3),(3);
457451

458-
explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 3);
459-
explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 0);
452+
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)');
453+
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)');
460454

461455
delete from lprt_a where a = 1;
462456

463-
explain (analyze, costs off, summary off, timing off) execute ab_q6 (1, 0, 0);
457+
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)');
464458

465459
reset enable_hashjoin;
466460
reset enable_mergejoin;
@@ -478,7 +472,6 @@ deallocate ab_q2;
478472
deallocate ab_q3;
479473
deallocate ab_q4;
480474
deallocate ab_q5;
481-
deallocate ab_q6;
482475

483476
drop table ab, lprt_a;
484477

0 commit comments

Comments
 (0)