Rely on plan_cache_mode to force generic plans in partition_prune test.

This file had a very weird mix of tests that did "set plan_cache_mode =
force_generic_plan" to get a generic plan, and tests that relied on
using five dummy executions of a prepared statement.  Converting them
all to rely on plan_cache_mode is more consistent and shaves off a
noticeable fraction of the test script's runtime.

Discussion: https://postgr.es/m/11952.1569536725@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2019-09-30 17:14:00 -04:00
parent 863fa43e32
commit d52eaa0948
2 changed files with 6 additions and 371 deletions

View File

@ -1,6 +1,8 @@
--
-- Test partitioning planner code
--
-- Force generic plans to be used for all prepared statements in this file.
set plan_cache_mode = force_generic_plan;
create table lp (a char) partition by list (a);
create table lp_default partition of lp default;
create table lp_ef partition of lp for values in ('e', 'f');
@ -1715,33 +1717,6 @@ create table ab_a3_b3 partition of ab_a3 for values in (3);
set enable_indexonlyscan = off;
prepare ab_q1 (int, int, int) as
select * from ab where a between $1 and $2 and b <= $3;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q1 (1, 8, 3);
a | b
---+---
(0 rows)
execute ab_q1 (1, 8, 3);
a | b
---+---
(0 rows)
execute ab_q1 (1, 8, 3);
a | b
---+---
(0 rows)
execute ab_q1 (1, 8, 3);
a | b
---+---
(0 rows)
execute ab_q1 (1, 8, 3);
a | b
---+---
(0 rows)
explain (analyze, costs off, summary off, timing off) execute ab_q1 (2, 2, 3);
QUERY PLAN
---------------------------------------------------------
@ -1778,33 +1753,6 @@ deallocate ab_q1;
-- Runtime pruning after optimizer pruning
prepare ab_q1 (int, int) as
select a from ab where a between $1 and $2 and b < 3;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q1 (1, 8);
a
---
(0 rows)
execute ab_q1 (1, 8);
a
---
(0 rows)
execute ab_q1 (1, 8);
a
---
(0 rows)
execute ab_q1 (1, 8);
a
---
(0 rows)
execute ab_q1 (1, 8);
a
---
(0 rows)
explain (analyze, costs off, summary off, timing off) execute ab_q1 (2, 2);
QUERY PLAN
-------------------------------------------------------
@ -1835,31 +1783,6 @@ explain (analyze, costs off, summary off, timing off) execute ab_q1 (2, 4);
-- different levels of partitioning.
prepare ab_q2 (int, int) as
select a from ab where a between $1 and $2 and b < (select 3);
execute ab_q2 (1, 8);
a
---
(0 rows)
execute ab_q2 (1, 8);
a
---
(0 rows)
execute ab_q2 (1, 8);
a
---
(0 rows)
execute ab_q2 (1, 8);
a
---
(0 rows)
execute ab_q2 (1, 8);
a
---
(0 rows)
explain (analyze, costs off, summary off, timing off) execute ab_q2 (2, 2);
QUERY PLAN
--------------------------------------------------------
@ -1878,31 +1801,6 @@ explain (analyze, costs off, summary off, timing off) execute ab_q2 (2, 2);
-- As above, but swap the PARAM_EXEC Param to the first partition level
prepare ab_q3 (int, int) as
select a from ab where b between $1 and $2 and a < (select 3);
execute ab_q3 (1, 8);
a
---
(0 rows)
execute ab_q3 (1, 8);
a
---
(0 rows)
execute ab_q3 (1, 8);
a
---
(0 rows)
execute ab_q3 (1, 8);
a
---
(0 rows)
execute ab_q3 (1, 8);
a
---
(0 rows)
explain (analyze, costs off, summary off, timing off) execute ab_q3 (2, 2);
QUERY PLAN
--------------------------------------------------------
@ -2021,38 +1919,6 @@ set parallel_setup_cost = 0;
set parallel_tuple_cost = 0;
set min_parallel_table_scan_size = 0;
set max_parallel_workers_per_gather = 2;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q4 (1, 8);
avg
-----
(1 row)
execute ab_q4 (1, 8);
avg
-----
(1 row)
execute ab_q4 (1, 8);
avg
-----
(1 row)
execute ab_q4 (1, 8);
avg
-----
(1 row)
execute ab_q4 (1, 8);
avg
-----
(1 row)
select explain_parallel_append('execute ab_q4 (2, 2)');
explain_parallel_append
-------------------------------------------------------------------------------
@ -2074,38 +1940,6 @@ select explain_parallel_append('execute ab_q4 (2, 2)');
-- Test run-time pruning with IN lists.
prepare ab_q5 (int, int, int) as
select avg(a) from ab where a in($1,$2,$3) and b < 4;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q5 (1, 2, 3);
avg
-----
(1 row)
execute ab_q5 (1, 2, 3);
avg
-----
(1 row)
execute ab_q5 (1, 2, 3);
avg
-----
(1 row)
execute ab_q5 (1, 2, 3);
avg
-----
(1 row)
execute ab_q5 (1, 2, 3);
avg
-----
(1 row)
select explain_parallel_append('execute ab_q5 (1, 1, 1)');
explain_parallel_append
-------------------------------------------------------------------------------
@ -2530,7 +2364,6 @@ create table xy_1 (x int, y int);
insert into xy_1 values(100,-10);
set enable_bitmapscan = 0;
set enable_indexscan = 0;
set plan_cache_mode = 'force_generic_plan';
prepare ab_q6 as
select * from (
select tableoid::regclass,a,b from ab
@ -2573,7 +2406,6 @@ execute ab_q6(100);
reset enable_bitmapscan;
reset enable_indexscan;
reset plan_cache_mode;
deallocate ab_q1;
deallocate ab_q2;
deallocate ab_q3;
@ -2956,33 +2788,6 @@ alter table part_bac attach partition part_cab for values in(2);
alter table part_cab attach partition part_abc_p1 for values in(3);
prepare part_abc_q1 (int, int, int) as
select * from part_abc where a = $1 and b = $2 and c = $3;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute part_abc_q1 (1, 2, 3);
a | b | c
---+---+---
(0 rows)
execute part_abc_q1 (1, 2, 3);
a | b | c
---+---+---
(0 rows)
execute part_abc_q1 (1, 2, 3);
a | b | c
---+---+---
(0 rows)
execute part_abc_q1 (1, 2, 3);
a | b | c
---+---+---
(0 rows)
execute part_abc_q1 (1, 2, 3);
a | b | c
---+---+---
(0 rows)
-- Single partition should be scanned.
explain (analyze, costs off, summary off, timing off) execute part_abc_q1 (1, 2, 3);
QUERY PLAN
@ -3009,31 +2814,6 @@ select * from listp where b = 1;
-- partitions before finally detecting the correct set of 2nd level partitions
-- which match the given parameter.
prepare q1 (int,int) as select * from listp where b in ($1,$2);
execute q1 (1,2);
a | b
---+---
(0 rows)
execute q1 (1,2);
a | b
---+---
(0 rows)
execute q1 (1,2);
a | b
---+---
(0 rows)
execute q1 (1,2);
a | b
---+---
(0 rows)
execute q1 (1,2);
a | b
---+---
(0 rows)
explain (analyze, costs off, summary off, timing off) execute q1 (1,1);
QUERY PLAN
-----------------------------------------------------
@ -3066,31 +2846,6 @@ explain (analyze, costs off, summary off, timing off) execute q1 (0,0);
deallocate q1;
-- Test more complex cases where a not-equal condition further eliminates partitions.
prepare q1 (int,int,int,int) as select * from listp where b in($1,$2) and $3 <> b and $4 <> b;
execute q1 (1,2,3,4);
a | b
---+---
(0 rows)
execute q1 (1,2,3,4);
a | b
---+---
(0 rows)
execute q1 (1,2,3,4);
a | b
---+---
(0 rows)
execute q1 (1,2,3,4);
a | b
---+---
(0 rows)
execute q1 (1,2,3,4);
a | b
---+---
(0 rows)
-- Both partitions allowed by IN clause, but one disallowed by <> clause
explain (analyze, costs off, summary off, timing off) execute q1 (1,2,2,0);
QUERY PLAN
@ -3259,7 +3014,6 @@ select * from mc3p where a < 3 and abs(b) = 1;
-- a combination of runtime parameters is specified, not all of whose values
-- are available at the same time
--
set plan_cache_mode = force_generic_plan;
prepare ps1 as
select * from mc3p where a = $1 and abs(b) < (select 3);
explain (analyze, costs off, summary off, timing off)
@ -3292,7 +3046,6 @@ execute ps2(1);
(8 rows)
deallocate ps2;
reset plan_cache_mode;
drop table mc3p;
-- Ensure runtime pruning works with initplans params with boolean types
create table boolvalues (value bool not null);
@ -3344,48 +3097,6 @@ insert into ma_test select x,x from generate_series(0,29) t(x);
create index on ma_test (b);
analyze ma_test;
prepare mt_q1 (int) as select a from ma_test where a >= $1 and a % 10 = 5 order by b;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute mt_q1(0);
a
----
5
15
25
(3 rows)
execute mt_q1(0);
a
----
5
15
25
(3 rows)
execute mt_q1(0);
a
----
5
15
25
(3 rows)
execute mt_q1(0);
a
----
5
15
25
(3 rows)
execute mt_q1(0);
a
----
5
15
25
(3 rows)
explain (analyze, costs off, summary off, timing off) execute mt_q1(15);
QUERY PLAN
-------------------------------------------------------------------------------
@ -3857,7 +3568,6 @@ from (
select 1, 1, 1
) s(a, b, c)
where s.a = $1 and s.b = $2 and s.c = (select 1);
set plan_cache_mode to force_generic_plan;
explain (costs off) execute q (1, 1);
QUERY PLAN
---------------------------------------------------------------
@ -3879,7 +3589,6 @@ execute q (1, 1);
1 | 1 | 1
(1 row)
reset plan_cache_mode;
drop table p, q;
-- Ensure run-time pruning works correctly when we match a partitioned table
-- on the first level but find no matching partitions on the second level.

View File

@ -1,6 +1,10 @@
--
-- Test partitioning planner code
--
-- Force generic plans to be used for all prepared statements in this file.
set plan_cache_mode = force_generic_plan;
create table lp (a char) partition by list (a);
create table lp_default partition of lp default;
create table lp_ef partition of lp for values in ('e', 'f');
@ -355,14 +359,6 @@ set enable_indexonlyscan = off;
prepare ab_q1 (int, int, int) as
select * from ab where a between $1 and $2 and b <= $3;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q1 (1, 8, 3);
execute ab_q1 (1, 8, 3);
execute ab_q1 (1, 8, 3);
execute ab_q1 (1, 8, 3);
execute ab_q1 (1, 8, 3);
explain (analyze, costs off, summary off, timing off) execute ab_q1 (2, 2, 3);
explain (analyze, costs off, summary off, timing off) execute ab_q1 (1, 2, 3);
@ -372,14 +368,6 @@ deallocate ab_q1;
prepare ab_q1 (int, int) as
select a from ab where a between $1 and $2 and b < 3;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q1 (1, 8);
execute ab_q1 (1, 8);
execute ab_q1 (1, 8);
execute ab_q1 (1, 8);
execute ab_q1 (1, 8);
explain (analyze, costs off, summary off, timing off) execute ab_q1 (2, 2);
explain (analyze, costs off, summary off, timing off) execute ab_q1 (2, 4);
@ -388,24 +376,12 @@ explain (analyze, costs off, summary off, timing off) execute ab_q1 (2, 4);
prepare ab_q2 (int, int) as
select a from ab where a between $1 and $2 and b < (select 3);
execute ab_q2 (1, 8);
execute ab_q2 (1, 8);
execute ab_q2 (1, 8);
execute ab_q2 (1, 8);
execute ab_q2 (1, 8);
explain (analyze, costs off, summary off, timing off) execute ab_q2 (2, 2);
-- As above, but swap the PARAM_EXEC Param to the first partition level
prepare ab_q3 (int, int) as
select a from ab where b between $1 and $2 and a < (select 3);
execute ab_q3 (1, 8);
execute ab_q3 (1, 8);
execute ab_q3 (1, 8);
execute ab_q3 (1, 8);
execute ab_q3 (1, 8);
explain (analyze, costs off, summary off, timing off) execute ab_q3 (2, 2);
-- Test a backwards Append scan
@ -485,27 +461,12 @@ set parallel_tuple_cost = 0;
set min_parallel_table_scan_size = 0;
set max_parallel_workers_per_gather = 2;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q4 (1, 8);
execute ab_q4 (1, 8);
execute ab_q4 (1, 8);
execute ab_q4 (1, 8);
execute ab_q4 (1, 8);
select explain_parallel_append('execute ab_q4 (2, 2)');
-- Test run-time pruning with IN lists.
prepare ab_q5 (int, int, int) as
select avg(a) from ab where a in($1,$2,$3) and b < 4;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute ab_q5 (1, 2, 3);
execute ab_q5 (1, 2, 3);
execute ab_q5 (1, 2, 3);
execute ab_q5 (1, 2, 3);
execute ab_q5 (1, 2, 3);
select explain_parallel_append('execute ab_q5 (1, 1, 1)');
select explain_parallel_append('execute ab_q5 (2, 3, 3)');
@ -579,7 +540,6 @@ insert into xy_1 values(100,-10);
set enable_bitmapscan = 0;
set enable_indexscan = 0;
set plan_cache_mode = 'force_generic_plan';
prepare ab_q6 as
select * from (
@ -598,7 +558,6 @@ execute ab_q6(100);
reset enable_bitmapscan;
reset enable_indexscan;
reset plan_cache_mode;
deallocate ab_q1;
deallocate ab_q2;
@ -712,14 +671,6 @@ alter table part_cab attach partition part_abc_p1 for values in(3);
prepare part_abc_q1 (int, int, int) as
select * from part_abc where a = $1 and b = $2 and c = $3;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute part_abc_q1 (1, 2, 3);
execute part_abc_q1 (1, 2, 3);
execute part_abc_q1 (1, 2, 3);
execute part_abc_q1 (1, 2, 3);
execute part_abc_q1 (1, 2, 3);
-- Single partition should be scanned.
explain (analyze, costs off, summary off, timing off) execute part_abc_q1 (1, 2, 3);
@ -741,12 +692,6 @@ select * from listp where b = 1;
-- which match the given parameter.
prepare q1 (int,int) as select * from listp where b in ($1,$2);
execute q1 (1,2);
execute q1 (1,2);
execute q1 (1,2);
execute q1 (1,2);
execute q1 (1,2);
explain (analyze, costs off, summary off, timing off) execute q1 (1,1);
explain (analyze, costs off, summary off, timing off) execute q1 (2,2);
@ -760,12 +705,6 @@ deallocate q1;
-- Test more complex cases where a not-equal condition further eliminates partitions.
prepare q1 (int,int,int,int) as select * from listp where b in($1,$2) and $3 <> b and $4 <> b;
execute q1 (1,2,3,4);
execute q1 (1,2,3,4);
execute q1 (1,2,3,4);
execute q1 (1,2,3,4);
execute q1 (1,2,3,4);
-- Both partitions allowed by IN clause, but one disallowed by <> clause
explain (analyze, costs off, summary off, timing off) execute q1 (1,2,2,0);
@ -842,7 +781,6 @@ select * from mc3p where a < 3 and abs(b) = 1;
-- a combination of runtime parameters is specified, not all of whose values
-- are available at the same time
--
set plan_cache_mode = force_generic_plan;
prepare ps1 as
select * from mc3p where a = $1 and abs(b) < (select 3);
explain (analyze, costs off, summary off, timing off)
@ -853,7 +791,6 @@ prepare ps2 as
explain (analyze, costs off, summary off, timing off)
execute ps2(1);
deallocate ps2;
reset plan_cache_mode;
drop table mc3p;
@ -888,14 +825,6 @@ create index on ma_test (b);
analyze ma_test;
prepare mt_q1 (int) as select a from ma_test where a >= $1 and a % 10 = 5 order by b;
-- Execute query 5 times to allow choose_custom_plan
-- to start considering a generic plan.
execute mt_q1(0);
execute mt_q1(0);
execute mt_q1(0);
execute mt_q1(0);
execute mt_q1(0);
explain (analyze, costs off, summary off, timing off) execute mt_q1(15);
execute mt_q1(15);
explain (analyze, costs off, summary off, timing off) execute mt_q1(25);
@ -1075,12 +1004,9 @@ from (
) s(a, b, c)
where s.a = $1 and s.b = $2 and s.c = (select 1);
set plan_cache_mode to force_generic_plan;
explain (costs off) execute q (1, 1);
execute q (1, 1);
reset plan_cache_mode;
drop table p, q;
-- Ensure run-time pruning works correctly when we match a partitioned table