8
8
</indexterm>
9
9
10
10
<para>
11
- <productname>PostgreSQL</productname> can devise query plans which can leverage
11
+ <productname>PostgreSQL</productname> can devise query plans that can leverage
12
12
multiple CPUs in order to answer queries faster. This feature is known
13
13
as parallel query. Many queries cannot benefit from parallel query, either
14
14
due to limitations of the current implementation or because there is no
15
- imaginable query plan which is any faster than the serial query plan.
15
+ imaginable query plan that is any faster than the serial query plan.
16
16
However, for queries that can benefit, the speedup from parallel query
17
17
is often very significant. Many queries can run more than twice as fast
18
18
when using parallel query, and some queries can run four times faster or
27
27
28
28
<para>
29
29
When the optimizer determines that parallel query is the fastest execution
30
- strategy for a particular query, it will create a query plan which includes
30
+ strategy for a particular query, it will create a query plan that includes
31
31
a <firstterm>Gather</firstterm> or <firstterm>Gather Merge</firstterm>
32
32
node. Here is a simple example:
33
33
@@ -59,7 +59,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
59
59
<para>
60
60
<link linkend="using-explain">Using EXPLAIN</link>, you can see the number of
61
61
workers chosen by the planner. When the <literal>Gather</literal> node is reached
62
- during query execution, the process which is implementing the user's
62
+ during query execution, the process that is implementing the user's
63
63
session will request a number of <link linkend="bgworker">background
64
64
worker processes</link> equal to the number
65
65
of workers chosen by the planner. The number of background workers that
@@ -79,7 +79,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
79
79
</para>
80
80
81
81
<para>
82
- Every background worker process which is successfully started for a given
82
+ Every background worker process that is successfully started for a given
83
83
parallel query will execute the parallel portion of the plan. The leader
84
84
will also execute that portion of the plan, but it has an additional
85
85
responsibility: it must also read all of the tuples generated by the
@@ -88,7 +88,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
88
88
worker, speeding up query execution. Conversely, when the parallel portion
89
89
of the plan generates a large number of tuples, the leader may be almost
90
90
entirely occupied with reading the tuples generated by the workers and
91
- performing any further processing steps which are required by plan nodes
91
+ performing any further processing steps that are required by plan nodes
92
92
above the level of the <literal>Gather</literal> node or
93
93
<literal>Gather Merge</literal> node. In such cases, the leader will
94
94
do very little of the work of executing the parallel portion of the plan.
@@ -109,7 +109,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
109
109
<title>When Can Parallel Query Be Used?</title>
110
110
111
111
<para>
112
- There are several settings which can cause the query planner not to
112
+ There are several settings that can cause the query planner not to
113
113
generate a parallel query plan under any circumstances. In order for
114
114
any parallel query plans whatsoever to be generated, the following
115
115
settings must be configured as indicated.
@@ -119,7 +119,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
119
119
<listitem>
120
120
<para>
121
121
<xref linkend="guc-max-parallel-workers-per-gather"/> must be set to a
122
- value which is greater than zero. This is a special case of the more
122
+ value that is greater than zero. This is a special case of the more
123
123
general principle that no more workers should be used than the number
124
124
configured via <varname>max_parallel_workers_per_gather</varname>.
125
125
</para>
@@ -144,8 +144,8 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
144
144
The query writes any data or locks any database rows. If a query
145
145
contains a data-modifying operation either at the top level or within
146
146
a CTE, no parallel plans for that query will be generated. As an
147
- exception, the following commands which create a new table and populate
148
- it can use a parallel plan for the underlying <literal>SELECT</literal>
147
+ exception, the following commands, which create a new table and populate
148
+ it, can use a parallel plan for the underlying <literal>SELECT</literal>
149
149
part of the query:
150
150
151
151
<itemizedlist>
@@ -255,7 +255,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
255
255
than normal but would produce incorrect results. Instead, the parallel
256
256
portion of the plan must be what is known internally to the query
257
257
optimizer as a <firstterm>partial plan</firstterm>; that is, it must be constructed
258
- so that each process which executes the plan will generate only a
258
+ so that each process that executes the plan will generate only a
259
259
subset of the output rows in such a way that each required output row
260
260
is guaranteed to be generated by exactly one of the cooperating processes.
261
261
Generally, this means that the scan on the driving table of the query
@@ -365,11 +365,11 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
365
365
366
366
<para>
367
367
Because the <literal>Finalize Aggregate</literal> node runs on the leader
368
- process, queries which produce a relatively large number of groups in
368
+ process, queries that produce a relatively large number of groups in
369
369
comparison to the number of input rows will appear less favorable to the
370
370
query planner. For example, in the worst-case scenario the number of
371
371
groups seen by the <literal>Finalize Aggregate</literal> node could be as many as
372
- the number of input rows which were seen by all worker processes in the
372
+ the number of input rows that were seen by all worker processes in the
373
373
<literal>Partial Aggregate</literal> stage. For such cases, there is clearly
374
374
going to be no performance benefit to using parallel aggregation. The
375
375
query planner takes this into account during the planning process and is
@@ -425,7 +425,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
425
425
involve appending multiple results sets can therefore achieve
426
426
coarse-grained parallelism even when efficient partial plans are not
427
427
available. For example, consider a query against a partitioned table
428
- which can only be implemented efficiently by using an index that does
428
+ that can only be implemented efficiently by using an index that does
429
429
not support parallel scans. The planner might choose a <literal>Parallel
430
430
Append</literal> of regular <literal>Index Scan</literal> plans; each
431
431
individual index scan would have to be executed to completion by a single
@@ -446,7 +446,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
446
446
If a query that is expected to do so does not produce a parallel plan,
447
447
you can try reducing <xref linkend="guc-parallel-setup-cost"/> or
448
448
<xref linkend="guc-parallel-tuple-cost"/>. Of course, this plan may turn
449
- out to be slower than the serial plan which the planner preferred, but
449
+ out to be slower than the serial plan that the planner preferred, but
450
450
this will not always be the case. If you don't get a parallel
451
451
plan even with very small values of these settings (e.g., after setting
452
452
them both to zero), there may be some reason why the query planner is
@@ -473,15 +473,15 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
473
473
<para>
474
474
The planner classifies operations involved in a query as either
475
475
<firstterm>parallel safe</firstterm>, <firstterm>parallel restricted</firstterm>,
476
- or <firstterm>parallel unsafe</firstterm>. A parallel safe operation is one which
476
+ or <firstterm>parallel unsafe</firstterm>. A parallel safe operation is one that
477
477
does not conflict with the use of parallel query. A parallel restricted
478
- operation is one which cannot be performed in a parallel worker, but which
478
+ operation is one that cannot be performed in a parallel worker, but that
479
479
can be performed in the leader while parallel query is in use. Therefore,
480
480
parallel restricted operations can never occur below a <literal>Gather</literal>
481
- or <literal>Gather Merge</literal> node, but can occur elsewhere in a plan which
482
- contains such a node. A parallel unsafe operation is one which cannot
481
+ or <literal>Gather Merge</literal> node, but can occur elsewhere in a plan that
482
+ contains such a node. A parallel unsafe operation is one that cannot
483
483
be performed while parallel query is in use, not even in the leader.
484
- When a query contains anything which is parallel unsafe, parallel query
484
+ When a query contains anything that is parallel unsafe, parallel query
485
485
is completely disabled for that query.
486
486
</para>
487
487
@@ -505,7 +505,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
505
505
<listitem>
506
506
<para>
507
507
Scans of foreign tables, unless the foreign data wrapper has
508
- an <literal>IsForeignScanParallelSafe</literal> API which indicates otherwise.
508
+ an <literal>IsForeignScanParallelSafe</literal> API that indicates otherwise.
509
509
</para>
510
510
</listitem>
511
511
@@ -517,7 +517,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
517
517
518
518
<listitem>
519
519
<para>
520
- Plan nodes which reference a correlated <literal>SubPlan</literal>.
520
+ Plan nodes that reference a correlated <literal>SubPlan</literal>.
521
521
</para>
522
522
</listitem>
523
523
</itemizedlist>
@@ -528,7 +528,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
528
528
<para>
529
529
The planner cannot automatically determine whether a user-defined
530
530
function or aggregate is parallel safe, parallel restricted, or parallel
531
- unsafe, because this would require predicting every operation which the
531
+ unsafe, because this would require predicting every operation that the
532
532
function could possibly perform. In general, this is equivalent to the
533
533
Halting Problem and therefore impossible. Even for simple functions
534
534
where it could conceivably be done, we do not try, since this would be expensive
@@ -546,11 +546,11 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
546
546
<para>
547
547
Functions and aggregates must be marked <literal>PARALLEL UNSAFE</literal> if
548
548
they write to the database, access sequences, change the transaction state
549
- even temporarily (e.g., a PL/pgSQL function which establishes an
549
+ even temporarily (e.g., a PL/pgSQL function that establishes an
550
550
<literal>EXCEPTION</literal> block to catch errors), or make persistent changes to
551
551
settings. Similarly, functions must be marked <literal>PARALLEL
552
552
RESTRICTED</literal> if they access temporary tables, client connection state,
553
- cursors, prepared statements, or miscellaneous backend-local state which
553
+ cursors, prepared statements, or miscellaneous backend-local state that
554
554
the system cannot synchronize across workers. For example,
555
555
<literal>setseed</literal> and <literal>random</literal> are parallel restricted for
556
556
this last reason.
@@ -568,10 +568,10 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
568
568
</para>
569
569
570
570
<para>
571
- If a function executed within a parallel worker acquires locks which are
571
+ If a function executed within a parallel worker acquires locks that are
572
572
not held by the leader, for example by querying a table not referenced in
573
573
the query, those locks will be released at worker exit, not end of
574
- transaction. If you write a function which does this, and this behavior
574
+ transaction. If you write a function that does this, and this behavior
575
575
difference is important to you, mark such functions as
576
576
<literal>PARALLEL RESTRICTED</literal>
577
577
to ensure that they execute only in the leader.
0 commit comments