@@ -659,31 +659,55 @@ set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
659
659
static void
660
660
create_parallel_paths (PlannerInfo * root , RelOptInfo * rel )
661
661
{
662
- int parallel_threshold = 1000 ;
663
- int parallel_degree = 1 ;
662
+ int parallel_degree = 1 ;
664
663
665
664
/*
666
- * If this relation is too small to be worth a parallel scan, just return
667
- * without doing anything ... unless it's an inheritance child. In that case,
668
- * we want to generate a parallel path here anyway. It might not be worthwhile
669
- * just for this relation, but when combined with all of its inheritance siblings
670
- * it may well pay off.
665
+ * If the user has set the parallel_degree reloption, we decide what to do
666
+ * based on the value of that option. Otherwise, we estimate a value.
671
667
*/
672
- if (rel -> pages < parallel_threshold && rel -> reloptkind == RELOPT_BASEREL )
673
- return ;
668
+ if (rel -> rel_parallel_degree != -1 )
669
+ {
670
+ /*
671
+ * If parallel_degree = 0 is set for this relation, bail out. The
672
+ * user does not want a parallel path for this relation.
673
+ */
674
+ if (rel -> rel_parallel_degree == 0 )
675
+ return ;
674
676
675
- /*
676
- * Limit the degree of parallelism logarithmically based on the size of the
677
- * relation. This probably needs to be a good deal more sophisticated, but we
678
- * need something here for now.
679
- */
680
- while ( rel -> pages > parallel_threshold * 3 &&
681
- parallel_degree < max_parallel_degree )
677
+ /*
678
+ * Use the table parallel_degree, but don't go further than
679
+ * max_parallel_degree.
680
+ */
681
+ parallel_degree = Min ( rel -> rel_parallel_degree , max_parallel_degree );
682
+ }
683
+ else
682
684
{
683
- parallel_degree ++ ;
684
- parallel_threshold *= 3 ;
685
- if (parallel_threshold >= PG_INT32_MAX / 3 )
686
- break ;
685
+ int parallel_threshold = 1000 ;
686
+
687
+ /*
688
+ * If this relation is too small to be worth a parallel scan, just
689
+ * return without doing anything ... unless it's an inheritance child.
690
+ * In that case, we want to generate a parallel path here anyway. It
691
+ * might not be worthwhile just for this relation, but when combined
692
+ * with all of its inheritance siblings it may well pay off.
693
+ */
694
+ if (rel -> pages < parallel_threshold &&
695
+ rel -> reloptkind == RELOPT_BASEREL )
696
+ return ;
697
+
698
+ /*
699
+ * Limit the degree of parallelism logarithmically based on the size
700
+ * of the relation. This probably needs to be a good deal more
701
+ * sophisticated, but we need something here for now.
702
+ */
703
+ while (rel -> pages > parallel_threshold * 3 &&
704
+ parallel_degree < max_parallel_degree )
705
+ {
706
+ parallel_degree ++ ;
707
+ parallel_threshold *= 3 ;
708
+ if (parallel_threshold >= PG_INT32_MAX / 3 )
709
+ break ;
710
+ }
687
711
}
688
712
689
713
/* Add an unordered partial path based on a parallel sequential scan. */
0 commit comments