@@ -669,27 +669,14 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
669669static void
670670create_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}
0 commit comments