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

Commit 639c1a6

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 820c030 commit 639c1a6

File tree

5 files changed

+7
-2
lines changed

5 files changed

+7
-2
lines changed

src/backend/executor/execMain.c

+1
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ ExecutePlan(EState *estate,
17021702
if (!execute_once)
17031703
use_parallel_mode = false;
17041704

1705+
estate->es_use_parallel_mode = use_parallel_mode;
17051706
if (use_parallel_mode)
17061707
EnterParallelMode();
17071708

src/backend/executor/execUtils.c

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ CreateExecutorState(void)
156156
estate->es_epqScanDone = NULL;
157157
estate->es_sourceText = NULL;
158158

159+
estate->es_use_parallel_mode = false;
160+
159161
/*
160162
* Return the executor state structure
161163
*/

src/backend/executor/nodeGather.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ ExecGather(PlanState *pstate)
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/backend/executor/nodeGatherMerge.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ ExecGatherMerge(PlanState *pstate)
194194
* Sometimes we might have to run without parallelism; but if parallel
195195
* mode is active then we can try to fire up some workers.
196196
*/
197-
if (gm->num_workers > 0 && IsInParallelMode())
197+
if (gm->num_workers > 0 && estate->es_use_parallel_mode)
198198
{
199199
ParallelContext *pcxt;
200200

src/include/nodes/execnodes.h

+2
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ typedef struct EState
507507
bool *es_epqTupleSet; /* true if EPQ tuple is provided */
508508
bool *es_epqScanDone; /* true if EPQ tuple has been fetched */
509509

510+
bool es_use_parallel_mode; /* can we use parallel workers? */
511+
510512
/* The per-query shared memory area to use for parallel execution. */
511513
struct dsa_area *es_query_dsa;
512514
} EState;

0 commit comments

Comments
 (0)