]> granicus.if.org Git - postgresql/blob - src/test/regress/sql/select_parallel.sql
Consider parallel merge joins.
[postgresql] / src / test / regress / sql / select_parallel.sql
1 --
2 -- PARALLEL
3 --
4
5 create or replace function parallel_restricted(int) returns int as
6   $$begin return $1; end$$ language plpgsql parallel restricted;
7
8 -- Serializable isolation would disable parallel query, so explicitly use an
9 -- arbitrary other level.
10 begin isolation level repeatable read;
11
12 -- encourage use of parallel plans
13 set parallel_setup_cost=0;
14 set parallel_tuple_cost=0;
15 set min_parallel_table_scan_size=0;
16 set max_parallel_workers_per_gather=4;
17
18 explain (costs off)
19   select count(*) from a_star;
20 select count(*) from a_star;
21
22 -- test that parallel_restricted function doesn't run in worker
23 alter table tenk1 set (parallel_workers = 4);
24 explain (verbose, costs off)
25 select parallel_restricted(unique1) from tenk1
26   where stringu1 = 'GRAAAA' order by 1;
27
28 -- test parallel plan when group by expression is in target list.
29 explain (costs off)
30         select length(stringu1) from tenk1 group by length(stringu1);
31 select length(stringu1) from tenk1 group by length(stringu1);
32
33 explain (costs off)
34         select stringu1, count(*) from tenk1 group by stringu1 order by stringu1;
35
36 -- test that parallel plan for aggregates is not selected when
37 -- target list contains parallel restricted clause.
38 explain (costs off)
39         select  sum(parallel_restricted(unique1)) from tenk1
40         group by(parallel_restricted(unique1));
41
42 -- test parallel plans for queries containing un-correlated subplans.
43 alter table tenk2 set (parallel_workers = 0);
44 explain (costs off)
45         select count(*) from tenk1 where (two, four) not in
46         (select hundred, thousand from tenk2 where thousand > 100);
47 select count(*) from tenk1 where (two, four) not in
48         (select hundred, thousand from tenk2 where thousand > 100);
49 alter table tenk2 reset (parallel_workers);
50
51 -- test parallel index scans.
52 set enable_seqscan to off;
53 set enable_bitmapscan to off;
54
55 explain (costs off)
56         select  count((unique1)) from tenk1 where hundred > 1;
57 select  count((unique1)) from tenk1 where hundred > 1;
58
59 -- test parallel index-only scans.
60 explain (costs off)
61         select  count(*) from tenk1 where thousand > 95;
62 select  count(*) from tenk1 where thousand > 95;
63
64 reset enable_seqscan;
65 reset enable_bitmapscan;
66
67 -- test parallel merge join path.
68 set enable_hashjoin to off;
69 set enable_nestloop to off;
70
71 explain (costs off)
72         select  count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1;
73 select  count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1;
74
75 reset enable_hashjoin;
76 reset enable_nestloop;
77 set force_parallel_mode=1;
78
79 explain (costs off)
80   select stringu1::int2 from tenk1 where unique1 = 1;
81
82 -- provoke error in worker
83 select stringu1::int2 from tenk1 where unique1 = 1;
84
85 rollback;