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-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;
|
2016-06-18 06:28:51 +02:00
|
|
|
set min_parallel_relation_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;
|
|
|
|
QUERY PLAN
|
|
|
|
-----------------------------------------------------
|
|
|
|
Finalize Aggregate
|
|
|
|
-> Gather
|
|
|
|
Workers Planned: 1
|
|
|
|
-> Partial Aggregate
|
|
|
|
-> Append
|
|
|
|
-> Parallel Seq Scan on a_star
|
|
|
|
-> Parallel Seq Scan on b_star
|
|
|
|
-> Parallel Seq Scan on c_star
|
|
|
|
-> Parallel Seq Scan on d_star
|
|
|
|
-> Parallel Seq Scan on e_star
|
|
|
|
-> Parallel Seq Scan on f_star
|
|
|
|
(11 rows)
|
|
|
|
|
|
|
|
select count(*) from a_star;
|
|
|
|
count
|
|
|
|
-------
|
|
|
|
50
|
|
|
|
(1 row)
|
|
|
|
|
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;
|
|
|
|
QUERY PLAN
|
|
|
|
---------------------------------------------------------
|
|
|
|
Sort
|
|
|
|
Output: (parallel_restricted(unique1))
|
|
|
|
Sort Key: (parallel_restricted(tenk1.unique1))
|
|
|
|
-> Gather
|
|
|
|
Output: parallel_restricted(unique1)
|
|
|
|
Workers Planned: 4
|
|
|
|
-> Parallel Seq Scan on public.tenk1
|
|
|
|
Output: unique1
|
|
|
|
Filter: (tenk1.stringu1 = 'GRAAAA'::name)
|
|
|
|
(9 rows)
|
|
|
|
|
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);
|
|
|
|
QUERY PLAN
|
|
|
|
---------------------------------------------------
|
|
|
|
Finalize HashAggregate
|
|
|
|
Group Key: (length((stringu1)::text))
|
|
|
|
-> Gather
|
|
|
|
Workers Planned: 4
|
|
|
|
-> Partial HashAggregate
|
|
|
|
Group Key: length((stringu1)::text)
|
|
|
|
-> Parallel Seq Scan on tenk1
|
|
|
|
(7 rows)
|
|
|
|
|
|
|
|
select length(stringu1) from tenk1 group by length(stringu1);
|
|
|
|
length
|
|
|
|
--------
|
|
|
|
6
|
|
|
|
(1 row)
|
|
|
|
|
2016-06-18 06:28:51 +02:00
|
|
|
explain (costs off)
|
|
|
|
select stringu1, count(*) from tenk1 group by stringu1 order by stringu1;
|
|
|
|
QUERY PLAN
|
|
|
|
----------------------------------------------------
|
|
|
|
Sort
|
|
|
|
Sort Key: stringu1
|
|
|
|
-> Finalize HashAggregate
|
|
|
|
Group Key: stringu1
|
|
|
|
-> Gather
|
|
|
|
Workers Planned: 4
|
|
|
|
-> Partial HashAggregate
|
|
|
|
Group Key: stringu1
|
|
|
|
-> Parallel Seq Scan on tenk1
|
|
|
|
(9 rows)
|
|
|
|
|
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));
|
|
|
|
QUERY PLAN
|
|
|
|
----------------------------------------------------
|
|
|
|
HashAggregate
|
|
|
|
Group Key: parallel_restricted(unique1)
|
|
|
|
-> Index Only Scan using tenk1_unique1 on tenk1
|
|
|
|
(3 rows)
|
|
|
|
|
2016-06-08 05:36:22 +02:00
|
|
|
set force_parallel_mode=1;
|
|
|
|
explain (costs off)
|
|
|
|
select stringu1::int2 from tenk1 where unique1 = 1;
|
|
|
|
QUERY PLAN
|
|
|
|
-----------------------------------------------
|
|
|
|
Gather
|
|
|
|
Workers Planned: 1
|
|
|
|
Single Copy: true
|
|
|
|
-> Index Scan using tenk1_unique1 on tenk1
|
|
|
|
Index Cond: (unique1 = 1)
|
|
|
|
(5 rows)
|
|
|
|
|
|
|
|
do $$begin
|
2016-06-17 15:24:29 +02:00
|
|
|
-- Provoke error, possibly in worker. If this error happens to occur in
|
|
|
|
-- the worker, there will be a CONTEXT line which must be hidden.
|
2016-06-15 20:59:07 +02:00
|
|
|
perform stringu1::int2 from tenk1 where unique1 = 1;
|
|
|
|
exception
|
|
|
|
when others then
|
|
|
|
raise 'SQLERRM: %', sqlerrm;
|
2016-06-08 05:36:22 +02:00
|
|
|
end$$;
|
2016-06-15 20:59:07 +02:00
|
|
|
ERROR: SQLERRM: invalid input syntax for integer: "BAAAAA"
|
|
|
|
CONTEXT: PL/pgSQL function inline_code_block line 7 at RAISE
|
2016-06-08 05:36:22 +02:00
|
|
|
rollback;
|