• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revisionf4e8b55ceae0f0d3b33f1822cffc9d7ed701ea30 (tree)
Time2017-06-06 20:07:39
AuthorKyotaro Horiguchi <horiguchi.kyotaro@lab....>
CommiterKyotaro Horiguchi

Log Message

Support PostgreSQL 10 beta 1 step 2/2

Changed the logic to tweak parallel execution paths so that it handles
more wider (parallel index scans or gather merge, specifically) range
of parallel paths.

Change Summary

Incremental Difference

--- a/expected/ut-W.out
+++ b/expected/ut-W.out
@@ -494,7 +494,7 @@ error hint:
494494 -> Parallel Seq Scan on p1_c3_c2
495495 (25 rows)
496496
497--- seqscan doesn't harm parallelism
497+-- Parallel sequential scan
498498 /*+Parallel(p1 8 hard) SeqScan(p1) */
499499 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
500500 LOG: pg_hint_plan:
@@ -534,7 +534,7 @@ error hint:
534534 -> Seq Scan on p2_c3_c2
535535 (25 rows)
536536
537--- Index partial scan is not handled yet.
537+-- Parallel index scan
538538 /*+Parallel(p1 8 hard) IndexScan(p1) */
539539 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
540540 LOG: pg_hint_plan:
@@ -545,32 +545,34 @@ not used hint:
545545 duplication hint:
546546 error hint:
547547
548- QUERY PLAN
549---------------------------------------------------------
550- Hash Join
551- Hash Cond: (p1.id = p2.id)
552- -> Append
553- -> Index Scan using p1_pkey on p1
554- -> Index Scan using p1_c1_pkey on p1_c1
555- -> Index Scan using p1_c2_pkey on p1_c2
556- -> Index Scan using p1_c3_pkey on p1_c3
557- -> Index Scan using p1_c4_pkey on p1_c4
558- -> Index Scan using p1_c1_c1_pkey on p1_c1_c1
559- -> Index Scan using p1_c1_c2_pkey on p1_c1_c2
560- -> Index Scan using p1_c3_c1_pkey on p1_c3_c1
561- -> Index Scan using p1_c3_c2_pkey on p1_c3_c2
562- -> Hash
548+ QUERY PLAN
549+-----------------------------------------------------------------------
550+ Gather
551+ Workers Planned: 8
552+ -> Hash Join
553+ Hash Cond: (p1.id = p2.id)
563554 -> Append
564- -> Seq Scan on p2
565- -> Seq Scan on p2_c1
566- -> Seq Scan on p2_c2
567- -> Seq Scan on p2_c3
568- -> Seq Scan on p2_c4
569- -> Seq Scan on p2_c1_c1
570- -> Seq Scan on p2_c1_c2
571- -> Seq Scan on p2_c3_c1
572- -> Seq Scan on p2_c3_c2
573-(23 rows)
555+ -> Parallel Index Scan using p1_pkey on p1
556+ -> Parallel Index Scan using p1_c1_pkey on p1_c1
557+ -> Parallel Index Scan using p1_c2_pkey on p1_c2
558+ -> Parallel Index Scan using p1_c3_pkey on p1_c3
559+ -> Parallel Index Scan using p1_c4_pkey on p1_c4
560+ -> Parallel Index Scan using p1_c1_c1_pkey on p1_c1_c1
561+ -> Parallel Index Scan using p1_c1_c2_pkey on p1_c1_c2
562+ -> Parallel Index Scan using p1_c3_c1_pkey on p1_c3_c1
563+ -> Parallel Index Scan using p1_c3_c2_pkey on p1_c3_c2
564+ -> Hash
565+ -> Append
566+ -> Seq Scan on p2
567+ -> Seq Scan on p2_c1
568+ -> Seq Scan on p2_c2
569+ -> Seq Scan on p2_c3
570+ -> Seq Scan on p2_c4
571+ -> Seq Scan on p2_c1_c1
572+ -> Seq Scan on p2_c1_c2
573+ -> Seq Scan on p2_c3_c1
574+ -> Seq Scan on p2_c3_c2
575+(25 rows)
574576
575577 -- This hint doesn't turn on parallel, so the Parallel hint is ignored
576578 set max_parallel_workers_per_gather TO 0;
--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -4433,50 +4433,24 @@ pg_hint_plan_set_rel_pathlist(PlannerInfo * root, RelOptInfo *rel,
44334433 return;
44344434
44354435 /* Here, we regenerate paths with the current hint restriction */
4436-
4437- if (found_hints & HINT_BM_SCAN_METHOD)
4436+ if (found_hints & HINT_BM_SCAN_METHOD || found_hints & HINT_BM_PARALLEL)
44384437 {
4439- /*
4440- * With scan hints, we regenerate paths for this relation from the
4441- * first under the restricion.
4442- */
4438+ /* Just discard all the paths considered so far */
44434439 list_free_deep(rel->pathlist);
44444440 rel->pathlist = NIL;
44454441
4446- set_plain_rel_pathlist(root, rel, rte);
4447- }
4448-
4449- if (found_hints & HINT_BM_PARALLEL)
4450- {
4451- Assert (phint);
4452-
4453- /* the partial_pathlist may be for different parameters, discard it */
4454- if (rel->partial_pathlist)
4442+ /* Remove all the partial paths if Parallel hint is specfied */
4443+ if ((found_hints & HINT_BM_PARALLEL) && rel->partial_pathlist)
44554444 {
44564445 list_free_deep(rel->partial_pathlist);
44574446 rel->partial_pathlist = NIL;
44584447 }
44594448
4460- /* also remove gather path */
4461- if (rel->pathlist)
4462- {
4463- ListCell *cell, *prev = NULL, *next;
4464-
4465- for (cell = list_head(rel->pathlist) ; cell; cell = next)
4466- {
4467- Path *path = (Path *) lfirst(cell);
4468-
4469- next = lnext(cell);
4470- if (IsA(path, GatherPath))
4471- rel->pathlist = list_delete_cell(rel->pathlist,
4472- cell, prev);
4473- else
4474- prev = cell;
4475- }
4476- }
4449+ /* Regenerate paths with the current enforcement */
4450+ set_plain_rel_pathlist(root, rel, rte);
44774451
4478- /* then generate new paths if needed */
4479- if (phint->nworkers > 0)
4452+ /* Additional work to enforce parallel query execution */
4453+ if (phint && phint->nworkers > 0)
44804454 {
44814455 /* Lower the priorities of non-parallel paths */
44824456 foreach (l, rel->pathlist)
@@ -4490,15 +4464,6 @@ pg_hint_plan_set_rel_pathlist(PlannerInfo * root, RelOptInfo *rel,
44904464 }
44914465 }
44924466
4493- /*
4494- * generate partial paths with enforcement, this is affected by
4495- * scan method enforcement. Specifically, the cost of this partial
4496- * seqscan path will be disabled_cost if seqscan is inhibited by
4497- * hint or GUC parameters.
4498- */
4499- Assert (rel->partial_pathlist == NIL);
4500- create_plain_partial_paths(root, rel);
4501-
45024467 /* enforce number of workers if requested */
45034468 if (phint->force_parallel)
45044469 {
--- a/sql/ut-W.sql
+++ b/sql/ut-W.sql
@@ -98,11 +98,11 @@ EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
9898 /*+Parallel(p1 8 hard) IndexScan(p2) */
9999 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
100100
101--- seqscan doesn't harm parallelism
101+-- Parallel sequential scan
102102 /*+Parallel(p1 8 hard) SeqScan(p1) */
103103 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
104104
105--- Index partial scan is not handled yet.
105+-- Parallel index scan
106106 /*+Parallel(p1 8 hard) IndexScan(p1) */
107107 EXPLAIN (COSTS false) SELECT * FROM p1 join p2 on p1.id = p2.id;
108108
Show on old repository browser