diff options
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r-- | src/backend/executor/execMain.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 37b7bbd413b..a55022e0a80 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -76,6 +76,7 @@ static void CheckValidRowMarkRel(Relation rel, RowMarkType markType); static void ExecPostprocessPlan(EState *estate); static void ExecEndPlan(PlanState *planstate, EState *estate); static void ExecutePlan(EState *estate, PlanState *planstate, + bool use_parallel_mode, CmdType operation, bool sendTuples, long numberTuples, @@ -243,11 +244,6 @@ standard_ExecutorStart(QueryDesc *queryDesc, int eflags) if (!(eflags & (EXEC_FLAG_SKIP_TRIGGERS | EXEC_FLAG_EXPLAIN_ONLY))) AfterTriggerBeginQuery(); - /* Enter parallel mode, if required by the query. */ - if (queryDesc->plannedstmt->parallelModeNeeded && - !(eflags & EXEC_FLAG_EXPLAIN_ONLY)) - EnterParallelMode(); - MemoryContextSwitchTo(oldcontext); } @@ -341,15 +337,13 @@ standard_ExecutorRun(QueryDesc *queryDesc, if (!ScanDirectionIsNoMovement(direction)) ExecutePlan(estate, queryDesc->planstate, + queryDesc->plannedstmt->parallelModeNeeded, operation, sendTuples, count, direction, dest); - /* Allow nodes to release or shut down resources. */ - (void) ExecShutdownNode(queryDesc->planstate); - /* * shutdown tuple receiver, if we started it */ @@ -482,11 +476,6 @@ standard_ExecutorEnd(QueryDesc *queryDesc) */ MemoryContextSwitchTo(oldcontext); - /* Exit parallel mode, if it was required by the query. */ - if (queryDesc->plannedstmt->parallelModeNeeded && - !(estate->es_top_eflags & EXEC_FLAG_EXPLAIN_ONLY)) - ExitParallelMode(); - /* * Release EState and per-query memory context. This should release * everything the executor has allocated. @@ -1529,6 +1518,7 @@ ExecEndPlan(PlanState *planstate, EState *estate) static void ExecutePlan(EState *estate, PlanState *planstate, + bool use_parallel_mode, CmdType operation, bool sendTuples, long numberTuples, @@ -1549,6 +1539,20 @@ ExecutePlan(EState *estate, estate->es_direction = direction; /* + * If a tuple count was supplied, we must force the plan to run without + * parallelism, because we might exit early. + */ + if (numberTuples != 0) + use_parallel_mode = false; + + /* + * If a tuple count was supplied, we must force the plan to run without + * parallelism, because we might exit early. + */ + if (use_parallel_mode) + EnterParallelMode(); + + /* * Loop until we've processed the proper number of tuples from the plan. */ for (;;) @@ -1566,7 +1570,11 @@ ExecutePlan(EState *estate, * process so we just end the loop... */ if (TupIsNull(slot)) + { + /* Allow nodes to release or shut down resources. */ + (void) ExecShutdownNode(planstate); break; + } /* * If we have a junk filter, then project a new tuple with the junk @@ -1603,6 +1611,9 @@ ExecutePlan(EState *estate, if (numberTuples && numberTuples == current_tuple_count) break; } + + if (use_parallel_mode) + ExitParallelMode(); } |