Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ebe5dc9

Browse files
committed
Fix interaction of parallel query with prepared statements.
Previously, a prepared statement created via a Parse message could get a parallel plan, but one created with a PREPARE statement could not. This state of affairs was due to confusion on my (rhaas) part: I erroneously believed that a CREATE TABLE .. AS EXECUTE statement could only be performed with a prepared statement by PREPARE, but in fact one created by a Prepare message works just as well. Therefore, it makes no sense to allow parallel query in one case but not the other. To fix, allow parallel query with all prepared statements, but run the parallel plan serially (i.e. without workers) in the case of CREATE TABLE .. AS EXECUTE. Also, document this. Amit Kapila and Tobias Bussman, plus an extra sentence of documentation by me.
1 parent e9e44a0 commit ebe5dc9

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

doc/src/sgml/parallel.sgml

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
218218
</para>
219219
</listitem>
220220

221+
<listitem>
222+
<para>
223+
A prepared statement is executed using a <literal>CREATE TABLE .. AS
224+
EXECUTE ..</literal> statement. This construct converts what otherwise
225+
would have been a read-only operation into a read-write operation,
226+
making it ineligible for parallel query.
227+
</para>
228+
</listitem>
229+
221230
<listitem>
222231
<para>
223232
The transaction isolation level is serializable. This situation

src/backend/commands/prepare.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString)
159159
nargs,
160160
NULL,
161161
NULL,
162-
0, /* default cursor options */
162+
CURSOR_OPT_PARALLEL_OK, /* allow parallel mode */
163163
true); /* fixed result */
164164

165165
/*

src/backend/executor/execMain.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1540,10 +1540,11 @@ ExecutePlan(EState *estate,
15401540
estate->es_direction = direction;
15411541

15421542
/*
1543-
* If a tuple count was supplied, we must force the plan to run without
1544-
* parallelism, because we might exit early.
1543+
* If a tuple count was supplied or data is being written to relation, we
1544+
* must force the plan to run without parallelism, because we might exit
1545+
* early.
15451546
*/
1546-
if (numberTuples)
1547+
if (numberTuples || dest->mydest == DestIntoRel)
15471548
use_parallel_mode = false;
15481549

15491550
/*

0 commit comments

Comments
 (0)