index 12d6dfcc55def28f7cf71e315c8badaf189d4b7f..3511181f6d38000354655b199d916c8737e6f1e0 100644 (file)
--
-- 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
---------------------------------------------------------
-- 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
--------------------------------------------------------
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
-------------------------------------------------------------------------------
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
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
-- 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
-- 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)
(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
-------------------------------------------------------------------------------
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
---------------------------------------------------------------
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.
index 8a0e72341eaf6224eb7876df2b01fc2a3a767589..b66e599575ed8b06f55521c47f6bd431ff2de8d0 100644 (file)
--
-- 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');
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);
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
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)');
set enable_bitmapscan = 0;
set enable_indexscan = 0;
-set plan_cache_mode = 'force_generic_plan';
prepare ab_q6 as
select * from (
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);
-- 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);
-- 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)
explain (analyze, costs off, summary off, timing off)
execute ps2(1);
deallocate ps2;
-reset plan_cache_mode;
drop table mc3p;
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);
) 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