Guard against parallel-restricted functions in VALUES expressions.
authorTom Lane
Fri, 19 Aug 2016 18:35:32 +0000 (14:35 -0400)
committerTom Lane
Fri, 19 Aug 2016 18:35:32 +0000 (14:35 -0400)
Obvious brain fade in set_rel_consider_parallel().  Noticed it while
adjusting the adjacent RTE_FUNCTION case.

In 9.6, also make the code look more like what I just did in HEAD
by removing the unnecessary function_rte_parallel_ok subroutine
(it does nothing that expression_tree_walker wouldn't do).

src/backend/optimizer/path/allpaths.c

index 88d833a2e89682b12eee1c4b1c50a4e7f47add1a..cceb27ee76c0ac444f574bb60215262fcbcb08f9 100644 (file)
@@ -78,7 +78,6 @@ static void set_plain_rel_size(PlannerInfo *root, RelOptInfo *rel,
 static void create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel);
 static void set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
                          RangeTblEntry *rte);
-static bool function_rte_parallel_ok(RangeTblEntry *rte);
 static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
                       RangeTblEntry *rte);
 static void set_tablesample_rel_size(PlannerInfo *root, RelOptInfo *rel,
@@ -596,16 +595,14 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
 
        case RTE_FUNCTION:
            /* Check for parallel-restricted functions. */
-           if (!function_rte_parallel_ok(rte))
+           if (has_parallel_hazard((Node *) rte->functions, false))
                return;
            break;
 
        case RTE_VALUES:
-
-           /*
-            * The data for a VALUES clause is stored in the plan tree itself,
-            * so scanning it in a worker is fine.
-            */
+           /* Check for parallel-restricted functions. */
+           if (has_parallel_hazard((Node *) rte->values_lists, false))
+               return;
            break;
 
        case RTE_CTE:
@@ -643,26 +640,6 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
    rel->consider_parallel = true;
 }
 
-/*
- * Check whether a function RTE is scanning something parallel-restricted.
- */
-static bool
-function_rte_parallel_ok(RangeTblEntry *rte)
-{
-   ListCell   *lc;
-
-   foreach(lc, rte->functions)
-   {
-       RangeTblFunction *rtfunc = (RangeTblFunction *) lfirst(lc);
-
-       Assert(IsA(rtfunc, RangeTblFunction));
-       if (has_parallel_hazard(rtfunc->funcexpr, false))
-           return false;
-   }
-
-   return true;
-}
-
 /*
  * set_plain_rel_pathlist
  *   Build access paths for a plain relation (no subquery, no inheritance)