diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-04-08 11:14:56 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-04-08 11:14:56 -0400 |
commit | 25fe8b5f1ac93c3ec01519854e4f554b2e57a926 (patch) | |
tree | 38e7e8d5bbe0d6f6ab67f19eb38d0e2e5fdcd9e5 /src/backend/optimizer/path/allpaths.c | |
parent | b0b64f65054e6b858b845b46298a624aaaea1deb (diff) |
Add a 'parallel_degree' reloption.
The code that estimates what parallel degree should be uesd for the
scan of a relation is currently rather stupid, so add a parallel_degree
reloption that can be used to override the planner's rather limited
judgement.
Julien Rouhaud, reviewed by David Rowley, James Sewell, Amit Kapila,
and me. Some further hacking by me.
Diffstat (limited to 'src/backend/optimizer/path/allpaths.c')
-rw-r--r-- | src/backend/optimizer/path/allpaths.c | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index cc77ff9e1f0..17c1edd9703 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -659,31 +659,55 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) static void create_parallel_paths(PlannerInfo *root, RelOptInfo *rel) { - int parallel_threshold = 1000; - int parallel_degree = 1; + int parallel_degree = 1; /* - * If this relation is too small to be worth a parallel scan, just return - * without doing anything ... unless it's an inheritance child. In that case, - * we want to generate a parallel path here anyway. It might not be worthwhile - * just for this relation, but when combined with all of its inheritance siblings - * it may well pay off. + * If the user has set the parallel_degree reloption, we decide what to do + * based on the value of that option. Otherwise, we estimate a value. */ - if (rel->pages < parallel_threshold && rel->reloptkind == RELOPT_BASEREL) - return; + if (rel->rel_parallel_degree != -1) + { + /* + * If parallel_degree = 0 is set for this relation, bail out. The + * user does not want a parallel path for this relation. + */ + if (rel->rel_parallel_degree == 0) + return; - /* - * Limit the degree of parallelism logarithmically based on the size of the - * relation. This probably needs to be a good deal more sophisticated, but we - * need something here for now. - */ - while (rel->pages > parallel_threshold * 3 && - parallel_degree < max_parallel_degree) + /* + * Use the table parallel_degree, but don't go further than + * max_parallel_degree. + */ + parallel_degree = Min(rel->rel_parallel_degree, max_parallel_degree); + } + else { - parallel_degree++; - parallel_threshold *= 3; - if (parallel_threshold >= PG_INT32_MAX / 3) - break; + int parallel_threshold = 1000; + + /* + * If this relation is too small to be worth a parallel scan, just + * return without doing anything ... unless it's an inheritance child. + * In that case, we want to generate a parallel path here anyway. It + * might not be worthwhile just for this relation, but when combined + * with all of its inheritance siblings it may well pay off. + */ + if (rel->pages < parallel_threshold && + rel->reloptkind == RELOPT_BASEREL) + return; + + /* + * Limit the degree of parallelism logarithmically based on the size + * of the relation. This probably needs to be a good deal more + * sophisticated, but we need something here for now. + */ + while (rel->pages > parallel_threshold * 3 && + parallel_degree < max_parallel_degree) + { + parallel_degree++; + parallel_threshold *= 3; + if (parallel_threshold >= PG_INT32_MAX / 3) + break; + } } /* Add an unordered partial path based on a parallel sequential scan. */ |