OSDN Git Service

Don't apply parallel hint on rels that planner considers unsafe.
authorKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Thu, 16 Feb 2017 10:08:54 +0000 (19:08 +0900)
committerKyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Tue, 21 Feb 2017 00:11:45 +0000 (09:11 +0900)
pg_hint_plan considered had its own decision logic on whether
parallel-safe or not but it is dangerous and unnecessary. Just follow
planner's decision.

expected/ut-W.out
pg_hint_plan.c
sql/ut-W.sql

index 0828d14..7eecc35 100644 (file)
@@ -568,13 +568,20 @@ error hint:
                ->  Seq Scan on p2_c3_c2
 (23 rows)
 
+-- This hint doesn't turn on parallel, so the Parallel hint is ignored
+show max_parallel_workers_per_gather;
+ max_parallel_workers_per_gather 
+---------------------------------
+ 0
+(1 row)
+
 /*+Parallel(p1 0 hard) IndexScan(p1) */
 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
 LOG:  pg_hint_plan:
 used hint:
 IndexScan(p1)
-Parallel(p1 0 hard)
 not used hint:
+Parallel(p1 0 hard)
 duplication hint:
 error hint:
 
index 6b747c8..477c1f1 100644 (file)
@@ -3089,16 +3089,17 @@ find_parallel_hint(PlannerInfo *root, Index relid)
        rel = root->simple_rel_array[relid];
 
        /*
-        * This function is called for any RelOptInfo or its inheritance parent if
-        * any. If we are called from inheritance planner, the RelOptInfo for the
-        * parent of target child relation is not set in the planner info.
-        *
-        * Otherwise we should check that the reloptinfo is base relation or
-        * inheritance children.
+        * Parallel planning is appliable only on base relation, which has
+        * RelOptInfo. 
         */
-       if (rel &&
-               rel->reloptkind != RELOPT_BASEREL &&
-               rel->reloptkind != RELOPT_OTHER_MEMBER_REL)
+       if (!rel)
+               return NULL;
+
+       /*
+        * We have set root->glob->parallelModeOK if needed. What we should do here
+        * is just following the decision of planner.
+        */
+       if (!rel->consider_parallel)
                return NULL;
 
        /*
@@ -3107,11 +3108,6 @@ find_parallel_hint(PlannerInfo *root, Index relid)
        rte = root->simple_rte_array[relid];
        Assert(rte);
 
-       /* We don't hint on other than relation and foreign tables */
-       if (rte->rtekind != RTE_RELATION ||
-               rte->relkind == RELKIND_FOREIGN_TABLE)
-               return NULL;
-
        /* Find parallel method hint, which matches given names, from the list. */
        for (i = 0; i < current_hint_state->num_hints[HINT_TYPE_PARALLEL]; i++)
        {
index 28cc247..8a35a8a 100644 (file)
@@ -99,6 +99,9 @@ EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
 -- we don't have parallel over index scans so far
 /*+Parallel(p1 8 hard) IndexScan(p1) */
 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
+
+-- This hint doesn't turn on parallel, so the Parallel hint is ignored
+show max_parallel_workers_per_gather;
 /*+Parallel(p1 0 hard) IndexScan(p1) */
 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;