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>
@@ -145,7 +145,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
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
147
exception, the commands <literal>CREATE TABLE ... AS</literal>, <literal>SELECT
148
- INTO</literal>, and <literal>CREATE MATERIALIZED VIEW</literal> which create a new
148
+ INTO</literal>, and <literal>CREATE MATERIALIZED VIEW</literal> that create a new
149
149
table and populate it can use a parallel plan.
150
150
</para>
151
151
</listitem>
@@ -240,7 +240,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
240
240
than normal but would produce incorrect results. Instead, the parallel
241
241
portion of the plan must be what is known internally to the query
242
242
optimizer as a <firstterm>partial plan</firstterm>; that is, it must be constructed
243
- so that each process which executes the plan will generate only a
243
+ so that each process that executes the plan will generate only a
244
244
subset of the output rows in such a way that each required output row
245
245
is guaranteed to be generated by exactly one of the cooperating processes.
246
246
Generally, this means that the scan on the driving table of the query
@@ -350,11 +350,11 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
350
350
351
351
<para>
352
352
Because the <literal>Finalize Aggregate</literal> node runs on the leader
353
- process, queries which produce a relatively large number of groups in
353
+ process, queries that produce a relatively large number of groups in
354
354
comparison to the number of input rows will appear less favorable to the
355
355
query planner. For example, in the worst-case scenario the number of
356
356
groups seen by the <literal>Finalize Aggregate</literal> node could be as many as
357
- the number of input rows which were seen by all worker processes in the
357
+ the number of input rows that were seen by all worker processes in the
358
358
<literal>Partial Aggregate</literal> stage. For such cases, there is clearly
359
359
going to be no performance benefit to using parallel aggregation. The
360
360
query planner takes this into account during the planning process and is
@@ -410,7 +410,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
410
410
involve appending multiple results sets can therefore achieve
411
411
coarse-grained parallelism even when efficient partial plans are not
412
412
available. For example, consider a query against a partitioned table
413
- which can only be implemented efficiently by using an index that does
413
+ that can only be implemented efficiently by using an index that does
414
414
not support parallel scans. The planner might choose a <literal>Parallel
415
415
Append</literal> of regular <literal>Index Scan</literal> plans; each
416
416
individual index scan would have to be executed to completion by a single
@@ -431,7 +431,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
431
431
If a query that is expected to do so does not produce a parallel plan,
432
432
you can try reducing <xref linkend="guc-parallel-setup-cost"/> or
433
433
<xref linkend="guc-parallel-tuple-cost"/>. Of course, this plan may turn
434
- out to be slower than the serial plan which the planner preferred, but
434
+ out to be slower than the serial plan that the planner preferred, but
435
435
this will not always be the case. If you don't get a parallel
436
436
plan even with very small values of these settings (e.g., after setting
437
437
them both to zero), there may be some reason why the query planner is
@@ -458,15 +458,15 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
458
458
<para>
459
459
The planner classifies operations involved in a query as either
460
460
<firstterm>parallel safe</firstterm>, <firstterm>parallel restricted</firstterm>,
461
- or <firstterm>parallel unsafe</firstterm>. A parallel safe operation is one which
461
+ or <firstterm>parallel unsafe</firstterm>. A parallel safe operation is one that
462
462
does not conflict with the use of parallel query. A parallel restricted
463
- operation is one which cannot be performed in a parallel worker, but which
463
+ operation is one that cannot be performed in a parallel worker, but that
464
464
can be performed in the leader while parallel query is in use. Therefore,
465
465
parallel restricted operations can never occur below a <literal>Gather</literal>
466
- or <literal>Gather Merge</literal> node, but can occur elsewhere in a plan which
467
- contains such a node. A parallel unsafe operation is one which cannot
466
+ or <literal>Gather Merge</literal> node, but can occur elsewhere in a plan that
467
+ contains such a node. A parallel unsafe operation is one that cannot
468
468
be performed while parallel query is in use, not even in the leader.
469
- When a query contains anything which is parallel unsafe, parallel query
469
+ When a query contains anything that is parallel unsafe, parallel query
470
470
is completely disabled for that query.
471
471
</para>
472
472
@@ -490,7 +490,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
490
490
<listitem>
491
491
<para>
492
492
Scans of foreign tables, unless the foreign data wrapper has
493
- an <literal>IsForeignScanParallelSafe</literal> API which indicates otherwise.
493
+ an <literal>IsForeignScanParallelSafe</literal> API that indicates otherwise.
494
494
</para>
495
495
</listitem>
496
496
@@ -502,7 +502,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
502
502
503
503
<listitem>
504
504
<para>
505
- Plan nodes which reference a correlated <literal>SubPlan</literal>.
505
+ Plan nodes that reference a correlated <literal>SubPlan</literal>.
506
506
</para>
507
507
</listitem>
508
508
</itemizedlist>
@@ -513,7 +513,7 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
513
513
<para>
514
514
The planner cannot automatically determine whether a user-defined
515
515
function or aggregate is parallel safe, parallel restricted, or parallel
516
- unsafe, because this would require predicting every operation which the
516
+ unsafe, because this would require predicting every operation that the
517
517
function could possibly perform. In general, this is equivalent to the
518
518
Halting Problem and therefore impossible. Even for simple functions
519
519
where it could conceivably be done, we do not try, since this would be expensive
@@ -531,11 +531,11 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
531
531
<para>
532
532
Functions and aggregates must be marked <literal>PARALLEL UNSAFE</literal> if
533
533
they write to the database, access sequences, change the transaction state
534
- even temporarily (e.g., a PL/pgSQL function which establishes an
534
+ even temporarily (e.g., a PL/pgSQL function that establishes an
535
535
<literal>EXCEPTION</literal> block to catch errors), or make persistent changes to
536
536
settings. Similarly, functions must be marked <literal>PARALLEL
537
537
RESTRICTED</literal> if they access temporary tables, client connection state,
538
- cursors, prepared statements, or miscellaneous backend-local state which
538
+ cursors, prepared statements, or miscellaneous backend-local state that
539
539
the system cannot synchronize across workers. For example,
540
540
<literal>setseed</literal> and <literal>random</literal> are parallel restricted for
541
541
this last reason.
@@ -553,10 +553,10 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
553
553
</para>
554
554
555
555
<para>
556
- If a function executed within a parallel worker acquires locks which are
556
+ If a function executed within a parallel worker acquires locks that are
557
557
not held by the leader, for example by querying a table not referenced in
558
558
the query, those locks will be released at worker exit, not end of
559
- transaction. If you write a function which does this, and this behavior
559
+ transaction. If you write a function that does this, and this behavior
560
560
difference is important to you, mark such functions as
561
561
<literal>PARALLEL RESTRICTED</literal>
562
562
to ensure that they execute only in the leader.
0 commit comments