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-10-27 22:22:39 +02:00
|
|
|
-- test prepared statement
|
|
|
|
prepare tenk1_count(integer) As select count((unique1)) from tenk1 where hundred > $1;
|
|
|
|
explain (costs off) execute tenk1_count(1);
|
|
|
|
execute tenk1_count(1);
|
|
|
|
deallocate tenk1_count;
|
|
|
|
|
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);
|
2017-04-18 21:43:56 +02:00
|
|
|
-- this is not parallel-safe due to use of random() within SubLink's testexpr:
|
|
|
|
explain (costs off)
|
|
|
|
select * from tenk1 where (unique1 + random())::integer not in
|
|
|
|
(select ten from tenk2);
|
2017-02-15 00:09:47 +01:00
|
|
|
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;
|
|
|
|
|
2017-02-19 11:23:59 +01:00
|
|
|
-- test parallel index-only scans.
|
|
|
|
explain (costs off)
|
|
|
|
select count(*) from tenk1 where thousand > 95;
|
|
|
|
select count(*) from tenk1 where thousand > 95;
|
|
|
|
|
2017-08-31 19:15:54 +02:00
|
|
|
-- test rescan cases too
|
|
|
|
set enable_material = false;
|
|
|
|
|
|
|
|
explain (costs off)
|
|
|
|
select * from
|
|
|
|
(select count(unique1) from tenk1 where hundred > 10) ss
|
|
|
|
right join (values (1),(2),(3)) v(x) on true;
|
|
|
|
select * from
|
|
|
|
(select count(unique1) from tenk1 where hundred > 10) ss
|
|
|
|
right join (values (1),(2),(3)) v(x) on true;
|
|
|
|
|
|
|
|
explain (costs off)
|
|
|
|
select * from
|
|
|
|
(select count(*) from tenk1 where thousand > 99) ss
|
|
|
|
right join (values (1),(2),(3)) v(x) on true;
|
|
|
|
select * from
|
|
|
|
(select count(*) from tenk1 where thousand > 99) ss
|
|
|
|
right join (values (1),(2),(3)) v(x) on true;
|
|
|
|
|
|
|
|
reset enable_material;
|
2017-02-15 19:53:24 +01:00
|
|
|
reset enable_seqscan;
|
|
|
|
reset enable_bitmapscan;
|
|
|
|
|
Support parallel bitmap heap scans.
The index is scanned by a single process, but then all cooperating
processes can iterate jointly over the resulting set of heap blocks.
In the future, we might also want to support using a parallel bitmap
index scan to set up for a parallel bitmap heap scan, but that's a
job for another day.
Dilip Kumar, with some corrections and cosmetic changes by me. The
larger patch set of which this is a part has been reviewed and tested
by (at least) Andres Freund, Amit Khandekar, Tushar Ahuja, Rafia
Sabih, Haribabu Kommi, Thomas Munro, and me.
Discussion: http://postgr.es/m/CAFiTN-uc4=0WxRGfCzs-xfkMYcSEWUC-Fon6thkJGjkh9i=13A@mail.gmail.com
2017-03-08 18:05:43 +01:00
|
|
|
-- test parallel bitmap heap scan.
|
|
|
|
set enable_seqscan to off;
|
|
|
|
set enable_indexscan to off;
|
2017-04-06 22:36:54 +02:00
|
|
|
set enable_hashjoin to off;
|
|
|
|
set enable_mergejoin to off;
|
|
|
|
set enable_material to off;
|
2017-04-06 23:21:39 +02:00
|
|
|
-- test prefetching, if the platform allows it
|
|
|
|
DO $$
|
|
|
|
BEGIN
|
|
|
|
SET effective_io_concurrency = 50;
|
|
|
|
EXCEPTION WHEN invalid_parameter_value THEN
|
|
|
|
END $$;
|
2017-04-06 22:36:54 +02:00
|
|
|
set work_mem='64kB'; --set small work mem to force lossy pages
|
Support parallel bitmap heap scans.
The index is scanned by a single process, but then all cooperating
processes can iterate jointly over the resulting set of heap blocks.
In the future, we might also want to support using a parallel bitmap
index scan to set up for a parallel bitmap heap scan, but that's a
job for another day.
Dilip Kumar, with some corrections and cosmetic changes by me. The
larger patch set of which this is a part has been reviewed and tested
by (at least) Andres Freund, Amit Khandekar, Tushar Ahuja, Rafia
Sabih, Haribabu Kommi, Thomas Munro, and me.
Discussion: http://postgr.es/m/CAFiTN-uc4=0WxRGfCzs-xfkMYcSEWUC-Fon6thkJGjkh9i=13A@mail.gmail.com
2017-03-08 18:05:43 +01:00
|
|
|
explain (costs off)
|
2017-04-06 22:36:54 +02:00
|
|
|
select count(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand=0;
|
|
|
|
select count(*) from tenk1, tenk2 where tenk1.hundred > 1 and tenk2.thousand=0;
|
|
|
|
|
|
|
|
create table bmscantest (a int, t text);
|
|
|
|
insert into bmscantest select r, 'fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' FROM generate_series(1,100000) r;
|
|
|
|
create index i_bmtest ON bmscantest(a);
|
|
|
|
select count(*) from bmscantest where a>1;
|
Support parallel bitmap heap scans.
The index is scanned by a single process, but then all cooperating
processes can iterate jointly over the resulting set of heap blocks.
In the future, we might also want to support using a parallel bitmap
index scan to set up for a parallel bitmap heap scan, but that's a
job for another day.
Dilip Kumar, with some corrections and cosmetic changes by me. The
larger patch set of which this is a part has been reviewed and tested
by (at least) Andres Freund, Amit Khandekar, Tushar Ahuja, Rafia
Sabih, Haribabu Kommi, Thomas Munro, and me.
Discussion: http://postgr.es/m/CAFiTN-uc4=0WxRGfCzs-xfkMYcSEWUC-Fon6thkJGjkh9i=13A@mail.gmail.com
2017-03-08 18:05:43 +01:00
|
|
|
|
|
|
|
reset enable_seqscan;
|
|
|
|
reset enable_indexscan;
|
2017-04-06 22:36:54 +02:00
|
|
|
reset enable_hashjoin;
|
|
|
|
reset enable_mergejoin;
|
|
|
|
reset enable_material;
|
|
|
|
reset effective_io_concurrency;
|
|
|
|
reset work_mem;
|
|
|
|
drop table bmscantest;
|
Support parallel bitmap heap scans.
The index is scanned by a single process, but then all cooperating
processes can iterate jointly over the resulting set of heap blocks.
In the future, we might also want to support using a parallel bitmap
index scan to set up for a parallel bitmap heap scan, but that's a
job for another day.
Dilip Kumar, with some corrections and cosmetic changes by me. The
larger patch set of which this is a part has been reviewed and tested
by (at least) Andres Freund, Amit Khandekar, Tushar Ahuja, Rafia
Sabih, Haribabu Kommi, Thomas Munro, and me.
Discussion: http://postgr.es/m/CAFiTN-uc4=0WxRGfCzs-xfkMYcSEWUC-Fon6thkJGjkh9i=13A@mail.gmail.com
2017-03-08 18:05:43 +01:00
|
|
|
|
2017-03-07 17:49:49 +01:00
|
|
|
-- test parallel merge join path.
|
|
|
|
set enable_hashjoin to off;
|
|
|
|
set enable_nestloop to off;
|
|
|
|
|
|
|
|
explain (costs off)
|
|
|
|
select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1;
|
|
|
|
select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1;
|
|
|
|
|
|
|
|
reset enable_hashjoin;
|
|
|
|
reset enable_nestloop;
|
2017-03-09 13:40:36 +01:00
|
|
|
|
2017-08-15 00:21:26 +02:00
|
|
|
-- test gather merge
|
|
|
|
set enable_hashagg = false;
|
2017-03-09 13:40:36 +01:00
|
|
|
|
|
|
|
explain (costs off)
|
2017-08-15 00:21:26 +02:00
|
|
|
select count(*) from tenk1 group by twenty;
|
2017-03-09 13:40:36 +01:00
|
|
|
|
2017-08-15 00:21:26 +02:00
|
|
|
select count(*) from tenk1 group by twenty;
|
2017-03-09 13:40:36 +01:00
|
|
|
|
2017-08-30 15:59:23 +02:00
|
|
|
--test rescan behavior of gather merge
|
|
|
|
set enable_material = false;
|
|
|
|
|
|
|
|
explain (costs off)
|
|
|
|
select * from
|
|
|
|
(select string4, count(unique2)
|
|
|
|
from tenk1 group by string4 order by string4) ss
|
|
|
|
right join (values (1),(2),(3)) v(x) on true;
|
|
|
|
|
|
|
|
select * from
|
|
|
|
(select string4, count(unique2)
|
|
|
|
from tenk1 group by string4 order by string4) ss
|
|
|
|
right join (values (1),(2),(3)) v(x) on true;
|
|
|
|
|
|
|
|
reset enable_material;
|
|
|
|
|
2017-08-29 19:12:23 +02:00
|
|
|
reset enable_hashagg;
|
|
|
|
|
|
|
|
-- gather merge test with a LIMIT
|
|
|
|
explain (costs off)
|
|
|
|
select fivethous from tenk1 order by fivethous limit 4;
|
|
|
|
|
|
|
|
select fivethous from tenk1 order by fivethous limit 4;
|
|
|
|
|
2017-08-15 00:21:26 +02:00
|
|
|
-- gather merge test with 0 worker
|
|
|
|
set max_parallel_workers = 0;
|
|
|
|
explain (costs off)
|
|
|
|
select string4 from tenk1 order by string4 limit 5;
|
|
|
|
select string4 from tenk1 order by string4 limit 5;
|
|
|
|
reset max_parallel_workers;
|
2017-03-09 13:40:36 +01:00
|
|
|
|
2017-08-25 02:42:49 +02:00
|
|
|
SAVEPOINT settings;
|
|
|
|
SET LOCAL force_parallel_mode = 1;
|
2016-06-08 05:36:22 +02:00
|
|
|
explain (costs off)
|
|
|
|
select stringu1::int2 from tenk1 where unique1 = 1;
|
2017-08-25 02:42:49 +02:00
|
|
|
ROLLBACK TO SAVEPOINT settings;
|
|
|
|
|
|
|
|
-- exercise record typmod remapping between backends
|
|
|
|
CREATE OR REPLACE FUNCTION make_record(n int)
|
|
|
|
RETURNS RECORD LANGUAGE plpgsql PARALLEL SAFE AS
|
|
|
|
$$
|
|
|
|
BEGIN
|
|
|
|
RETURN CASE n
|
|
|
|
WHEN 1 THEN ROW(1)
|
|
|
|
WHEN 2 THEN ROW(1, 2)
|
|
|
|
WHEN 3 THEN ROW(1, 2, 3)
|
|
|
|
WHEN 4 THEN ROW(1, 2, 3, 4)
|
|
|
|
ELSE ROW(1, 2, 3, 4, 5)
|
|
|
|
END;
|
|
|
|
END;
|
|
|
|
$$;
|
|
|
|
SAVEPOINT settings;
|
|
|
|
SET LOCAL force_parallel_mode = 1;
|
|
|
|
SELECT make_record(x) FROM (SELECT generate_series(1, 5) x) ss ORDER BY x;
|
|
|
|
ROLLBACK TO SAVEPOINT settings;
|
|
|
|
DROP function make_record(n int);
|
2016-06-08 05:36:22 +02:00
|
|
|
|
2017-04-06 22:44:48 +02:00
|
|
|
-- to increase the parallel query test coverage
|
2017-08-25 02:42:49 +02:00
|
|
|
SAVEPOINT settings;
|
|
|
|
SET LOCAL force_parallel_mode = 1;
|
2017-04-06 22:44:48 +02:00
|
|
|
EXPLAIN (analyze, timing off, summary off, costs off) SELECT * FROM tenk1;
|
2017-08-25 02:42:49 +02:00
|
|
|
ROLLBACK TO SAVEPOINT settings;
|
2017-04-06 22:44:48 +02:00
|
|
|
|
2016-08-22 18:00:00 +02:00
|
|
|
-- provoke error in worker
|
2017-08-25 02:42:49 +02:00
|
|
|
SAVEPOINT settings;
|
|
|
|
SET LOCAL force_parallel_mode = 1;
|
2016-08-22 18:00:00 +02:00
|
|
|
select stringu1::int2 from tenk1 where unique1 = 1;
|
2017-08-25 02:42:49 +02:00
|
|
|
ROLLBACK TO SAVEPOINT settings;
|
2016-06-08 05:36:22 +02:00
|
|
|
|
|
|
|
rollback;
|