Skip to content

Commit e415831

Browse files
committed
Mop-up for parallel degree-ectomy.
Fix a couple of overlooked uses of "degree" terminology. Make the parallel worker count selection logic in create_plain_partial_paths more robust (in particular, it failed with max_parallel_workers_per_gather set to zero).
1 parent c9ce4a1 commit e415831

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -669,27 +669,14 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
669669
static void
670670
create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
671671
{
672-
int parallel_workers = 1;
672+
int parallel_workers;
673673

674674
/*
675-
* If the user has set the parallel_workers reloption, we decide what to do
676-
* based on the value of that option. Otherwise, we estimate a value.
675+
* If the user has set the parallel_workers reloption, use that; otherwise
676+
* select a default number of workers.
677677
*/
678678
if (rel->rel_parallel_workers != -1)
679-
{
680-
/*
681-
* If parallel_workers = 0 is set for this relation, bail out. The
682-
* user does not want a parallel path for this relation.
683-
*/
684-
if (rel->rel_parallel_workers == 0)
685-
return;
686-
687-
/*
688-
* Use the table parallel_workers, but don't go further than
689-
* max_parallel_workers_per_gather.
690-
*/
691-
parallel_workers = Min(rel->rel_parallel_workers, max_parallel_workers_per_gather);
692-
}
679+
parallel_workers = rel->rel_parallel_workers;
693680
else
694681
{
695682
int parallel_threshold = 1000;
@@ -706,20 +693,29 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
706693
return;
707694

708695
/*
709-
* Limit the degree of parallelism logarithmically based on the size
710-
* of the relation. This probably needs to be a good deal more
696+
* Select the number of workers based on the log of the size of the
697+
* relation. This probably needs to be a good deal more
711698
* sophisticated, but we need something here for now.
712699
*/
713-
while (rel->pages > parallel_threshold * 3 &&
714-
parallel_workers < max_parallel_workers_per_gather)
700+
parallel_workers = 1;
701+
while (rel->pages > parallel_threshold * 3)
715702
{
716703
parallel_workers++;
717704
parallel_threshold *= 3;
718705
if (parallel_threshold >= PG_INT32_MAX / 3)
719-
break;
706+
break; /* avoid overflow */
720707
}
721708
}
722709

710+
/*
711+
* In no case use more than max_parallel_workers_per_gather workers.
712+
*/
713+
parallel_workers = Min(parallel_workers, max_parallel_workers_per_gather);
714+
715+
/* If any limit was set to zero, the user doesn't want a parallel scan. */
716+
if (parallel_workers <= 0)
717+
return;
718+
723719
/* Add an unordered partial path based on a parallel sequential scan. */
724720
add_partial_path(rel, create_seqscan_path(root, rel, NULL, parallel_workers));
725721
}

src/backend/optimizer/util/plancat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
128128
estimate_rel_size(relation, rel->attr_widths - rel->min_attr,
129129
&rel->pages, &rel->tuples, &rel->allvisfrac);
130130

131-
/* Retrive the parallel_workers reloption, if set. */
132-
rel->rel_parallel_workers = RelationGetParallelDegree(relation, -1);
131+
/* Retrieve the parallel_workers reloption, or -1 if not set. */
132+
rel->rel_parallel_workers = RelationGetParallelWorkers(relation, -1);
133133

134134
/*
135135
* Make list of indexes. Ignore indexes on system catalogs if told to.

src/include/utils/rel.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,20 @@ typedef struct StdRdOptions
235235
/*
236236
* RelationIsUsedAsCatalogTable
237237
* Returns whether the relation should be treated as a catalog table
238-
* from the pov of logical decoding. Note multiple eval or argument!
238+
* from the pov of logical decoding. Note multiple eval of argument!
239239
*/
240240
#define RelationIsUsedAsCatalogTable(relation) \
241241
((relation)->rd_options ? \
242242
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
243243

244244
/*
245-
* RelationGetParallelDegree
246-
* Returns the relation's parallel_workers. Note multiple eval of argument!
245+
* RelationGetParallelWorkers
246+
* Returns the relation's parallel_workers reloption setting.
247+
* Note multiple eval of argument!
247248
*/
248-
#define RelationGetParallelDegree(relation, defaultpd) \
249+
#define RelationGetParallelWorkers(relation, defaultpw) \
249250
((relation)->rd_options ? \
250-
((StdRdOptions *) (relation)->rd_options)->parallel_workers : (defaultpd))
251+
((StdRdOptions *) (relation)->rd_options)->parallel_workers : (defaultpw))
251252

252253

253254
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy