Skip to content

Commit 036b6bd

Browse files
committed
Fix mistaken failure to allow parallelism in corner case.
If we try to run a parallel plan in serial mode because, for example, it's going to be scanned via a cursor, but for some reason we're already in parallel mode (for example because an outer query is running in parallel), we'd incorrectly try to launch workers. Fix by adding a flag to the EState, so that we can be certain that ExecutePlan() and ExecGather()/ExecGatherMerge() will have the same idea about whether we are executing serially or in parallel. Report and fix by Amit Kapila with help from Kuntal Ghosh. A few tweaks by me. Discussion: http://postgr.es/m/CAA4eK1+_BuZrmVCeua5Eqnm4Co9DAXdM5HPAOE2J19ePbR912Q@mail.gmail.com
1 parent 37b4e0f commit 036b6bd

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/backend/executor/execMain.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,10 +1548,7 @@ ExecutePlan(EState *estate,
15481548
if (numberTuples || dest->mydest == DestIntoRel)
15491549
use_parallel_mode = false;
15501550

1551-
/*
1552-
* If a tuple count was supplied, we must force the plan to run without
1553-
* parallelism, because we might exit early.
1554-
*/
1551+
estate->es_use_parallel_mode = use_parallel_mode;
15551552
if (use_parallel_mode)
15561553
EnterParallelMode();
15571554

src/backend/executor/execUtils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ CreateExecutorState(void)
140140
estate->es_epqTupleSet = NULL;
141141
estate->es_epqScanDone = NULL;
142142

143+
estate->es_use_parallel_mode = false;
144+
143145
/*
144146
* Return the executor state structure
145147
*/

src/backend/executor/nodeGather.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ ExecGather(GatherState *node)
150150
* Sometimes we might have to run without parallelism; but if parallel
151151
* mode is active then we can try to fire up some workers.
152152
*/
153-
if (gather->num_workers > 0 && IsInParallelMode())
153+
if (gather->num_workers > 0 && estate->es_use_parallel_mode)
154154
{
155155
ParallelContext *pcxt;
156156

src/include/nodes/execnodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ typedef struct EState
421421
HeapTuple *es_epqTuple; /* array of EPQ substitute tuples */
422422
bool *es_epqTupleSet; /* true if EPQ tuple is provided */
423423
bool *es_epqScanDone; /* true if EPQ tuple has been fetched */
424+
425+
bool es_use_parallel_mode; /* can we use parallel workers? */
424426
} EState;
425427

426428

0 commit comments

Comments
 (0)