@@ -669,27 +669,14 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
669
669
static void
670
670
create_plain_partial_paths (PlannerInfo * root , RelOptInfo * rel )
671
671
{
672
- int parallel_workers = 1 ;
672
+ int parallel_workers ;
673
673
674
674
/*
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 .
677
677
*/
678
678
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 ;
693
680
else
694
681
{
695
682
int parallel_threshold = 1000 ;
@@ -706,20 +693,29 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
706
693
return ;
707
694
708
695
/*
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
711
698
* sophisticated, but we need something here for now.
712
699
*/
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 )
715
702
{
716
703
parallel_workers ++ ;
717
704
parallel_threshold *= 3 ;
718
705
if (parallel_threshold >= PG_INT32_MAX / 3 )
719
- break ;
706
+ break ; /* avoid overflow */
720
707
}
721
708
}
722
709
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
+
723
719
/* Add an unordered partial path based on a parallel sequential scan. */
724
720
add_partial_path (rel , create_seqscan_path (root , rel , NULL , parallel_workers ));
725
721
}
0 commit comments