2016-06-08 05:36:22 +02:00
|
|
|
--
|
|
|
|
-- PARALLEL
|
|
|
|
--
|
|
|
|
|
2016-06-17 14:35:47 +02:00
|
|
|
create or replace function parallel_restricted(int) returns int as
|
|
|
|
$$begin return $1; end$$ language plpgsql parallel restricted;
|
2016-06-16 18:00:55 +02:00
|
|
|
|
2016-06-08 05:36:22 +02:00
|
|
|
-- Serializable isolation would disable parallel query, so explicitly use an
|
|
|
|
-- arbitrary other level.
|
|
|
|
begin isolation level repeatable read;
|
|
|
|
|
2016-06-18 06:28:51 +02:00
|
|
|
-- encourage use of parallel plans
|
2016-06-08 05:36:22 +02:00
|
|
|
set parallel_setup_cost=0;
|
|
|
|
set parallel_tuple_cost=0;
|
Replace min_parallel_relation_size with two new GUCs.
When min_parallel_relation_size was added, the only supported type
of parallel scan was a parallel sequential scan, but there are
pending patches for parallel index scan, parallel index-only scan,
and parallel bitmap heap scan. Those patches introduce two new
types of complications: first, what's relevant is not really the
total size of the relation but the portion of it that we will scan;
and second, index pages and heap pages shouldn't necessarily be
treated in exactly the same way. Typically, the number of index
pages will be quite small, but that doesn't necessarily mean that
a parallel index scan can't pay off.
Therefore, we introduce min_parallel_table_scan_size, which works
out a degree of parallelism for scans based on the number of table
pages that will be scanned (and which is therefore equivalent to
min_parallel_relation_size for parallel sequential scans) and also
min_parallel_index_scan_size which can be used to work out a degree
of parallelism based on the number of index pages that will be
scanned.
Amit Kapila and Robert Haas
Discussion: http://postgr.es/m/CAA4eK1KowGSYYVpd2qPpaPPA5R90r++QwDFbrRECTE9H_HvpOg@mail.gmail.com
Discussion: http://postgr.es/m/CAA4eK1+TnM4pXQbvn7OXqam+k_HZqb0ROZUMxOiL6DWJYCyYow@mail.gmail.com
2017-02-15 19:37:24 +01:00
|
|
|
set min_parallel_table_scan_size=0;
|
2016-06-16 18:00:55 +02:00
|
|
|
set max_parallel_workers_per_gather=4;
|
2016-06-08 05:36:22 +02:00
|
|
|
|
|
|
|
explain (costs off)
|
|
|
|
select count(*) from a_star;
|
|
|
|
select count(*) from a_star;
|
|
|
|
|
2016-06-16 18:00:55 +02:00
|
|
|
-- test that parallel_restricted function doesn't run in worker
|
|
|
|
alter table tenk1 set (parallel_workers = 4);
|
|
|
|
explain (verbose, costs off)
|
|
|
|
select parallel_restricted(unique1) from tenk1
|
|
|
|
where stringu1 = 'GRAAAA' order by 1;
|
|
|
|
|
2016-06-17 22:25:02 +02:00
|
|
|
-- test parallel plan when group by expression is in target list.
|
|
|
|
explain (costs off)
|
|
|
|
select length(stringu1) from tenk1 group by length(stringu1);
|
|
|
|
select length(stringu1) from tenk1 group by length(stringu1);
|
|
|
|
|
2016-06-18 06:28:51 +02:00
|
|
|
explain (costs off)
|
|
|
|
select stringu1, count(*) from tenk1 group by stringu1 order by stringu1;
|
|
|
|
|
2016-06-17 22:25:02 +02:00
|
|
|
-- test that parallel plan for aggregates is not selected when
|
|
|
|
-- target list contains parallel restricted clause.
|
|
|
|
explain (costs off)
|
|
|
|
select sum(parallel_restricted(unique1)) from tenk1
|
|
|
|
group by(parallel_restricted(unique1));
|
|
|
|
|
2017-02-15 00:09:47 +01:00
|
|
|
-- test parallel plans for queries containing un-correlated subplans.
|
|
|
|
alter table tenk2 set (parallel_workers = 0);
|
|
|
|
explain (costs off)
|
|
|
|
select count(*) from tenk1 where (two, four) not in
|
|
|
|
(select hundred, thousand from tenk2 where thousand > 100);
|
|
|
|
select count(*) from tenk1 where (two, four) not in
|
|
|
|
(select hundred, thousand from tenk2 where thousand > 100);
|
|
|
|
alter table tenk2 reset (parallel_workers);
|
|
|
|
|
2017-02-15 19:53:24 +01:00
|
|
|
-- test parallel index scans.
|
|
|
|
set enable_seqscan to off;
|
|
|
|
set enable_bitmapscan to off;
|
|
|
|
|
|
|
|
explain (costs off)
|
|
|
|
select count((unique1)) from tenk1 where hundred > 1;
|
|
|
|
select count((unique1)) from tenk1 where hundred > 1;
|
|
|
|
|
|
|
|
reset enable_seqscan;
|
|
|
|
reset enable_bitmapscan;
|
|
|
|
|
2016-06-08 05:36:22 +02:00
|
|
|
set force_parallel_mode=1;
|
|
|
|
|
|
|
|
explain (costs off)
|
|
|
|
select stringu1::int2 from tenk1 where unique1 = 1;
|
|
|
|
|
2016-08-22 18:00:00 +02:00
|
|
|
-- provoke error in worker
|
|
|
|
select stringu1::int2 from tenk1 where unique1 = 1;
|
2016-06-08 05:36:22 +02:00
|
|
|
|
|
|
|
rollback;
|