]> granicus.if.org Git - postgresql/commitdiff
Fix mistaken failure to allow parallelism in corner case.
authorRobert Haas <rhaas@postgresql.org>
Fri, 27 Oct 2017 14:04:01 +0000 (16:04 +0200)
committerRobert Haas <rhaas@postgresql.org>
Fri, 27 Oct 2017 14:12:16 +0000 (16:12 +0200)
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

src/backend/executor/execMain.c
src/backend/executor/execUtils.c
src/backend/executor/nodeGather.c
src/include/nodes/execnodes.h

index 09b8169b6c79479deea9e454b63a11a660219ae2..d8b46a11f4548cbbdb69cb76f4ba8e4c64471475 100644 (file)
@@ -1548,10 +1548,7 @@ ExecutePlan(EState *estate,
        if (numberTuples || dest->mydest == DestIntoRel)
                use_parallel_mode = false;
 
-       /*
-        * If a tuple count was supplied, we must force the plan to run without
-        * parallelism, because we might exit early.
-        */
+       estate->es_use_parallel_mode = use_parallel_mode;
        if (use_parallel_mode)
                EnterParallelMode();
 
index a3bcb100daddafc6e8983a35ef83bfea316483bb..54c60a8d445c6527fea1fbe2f0977fd27d544091 100644 (file)
@@ -140,6 +140,8 @@ CreateExecutorState(void)
        estate->es_epqTupleSet = NULL;
        estate->es_epqScanDone = NULL;
 
+       estate->es_use_parallel_mode = false;
+
        /*
         * Return the executor state structure
         */
index 7342aadfbb440a7b2721110c847c6ede7aa61e65..216759aeab1a6df14685428119c7bbe6bbe17615 100644 (file)
@@ -150,7 +150,7 @@ ExecGather(GatherState *node)
                 * Sometimes we might have to run without parallelism; but if parallel
                 * mode is active then we can try to fire up some workers.
                 */
-               if (gather->num_workers > 0 && IsInParallelMode())
+               if (gather->num_workers > 0 && estate->es_use_parallel_mode)
                {
                        ParallelContext *pcxt;
 
index 53a247ca5df27d4598000badf011b2e5acf4ee4f..7621a171671b8afa1245f9e095d9d509f4c97968 100644 (file)
@@ -421,6 +421,8 @@ typedef struct EState
        HeapTuple  *es_epqTuple;        /* array of EPQ substitute tuples */
        bool       *es_epqTupleSet; /* true if EPQ tuple is provided */
        bool       *es_epqScanDone; /* true if EPQ tuple has been fetched */
+
+       bool            es_use_parallel_mode; /* can we use parallel workers? */
 } EState;