From e701eee8123682aae4fec5dc9639b50a54eb0b35 Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi Date: Thu, 16 Feb 2017 19:08:54 +0900 Subject: [PATCH] Don't apply parallel hint on rels that planner considers unsafe. 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 | 9 ++++++++- pg_hint_plan.c | 24 ++++++++++-------------- sql/ut-W.sql | 3 +++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/expected/ut-W.out b/expected/ut-W.out index 0828d14..7eecc35 100644 --- a/expected/ut-W.out +++ b/expected/ut-W.out @@ -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: diff --git a/pg_hint_plan.c b/pg_hint_plan.c index 6b747c8..477c1f1 100644 --- a/pg_hint_plan.c +++ b/pg_hint_plan.c @@ -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++) { diff --git a/sql/ut-W.sql b/sql/ut-W.sql index 28cc247..8a35a8a 100644 --- a/sql/ut-W.sql +++ b/sql/ut-W.sql @@ -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; -- 2.11.0