diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 017cafb..0bd8bc9 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -966,9 +966,6 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel, continue; } - /* Copy consider_parallel flag from parent. */ - childrel->consider_parallel = rel->consider_parallel; - /* * CE failed, so finish copying/modifying targetlist and join quals. * @@ -989,6 +986,24 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel, appinfo); /* + * baserestrictinfo or reltarget for childrel may have been modified, + * so check if any one of those contains parallel-restricted clause. + * Even if one of the child rels is not parallel safe, parent rel + * should not be considred for parallelization. + */ + if (root->glob->parallelModeOK && rel->consider_parallel) + { + if (has_parallel_hazard((Node *) childrel->baserestrictinfo, false) || + has_parallel_hazard((Node *) childrel->reltarget->exprs, false)) + { + childrel->consider_parallel = false; + rel->consider_parallel = false; + } + else + childrel->consider_parallel = true; + } + + /* * We have to make child entries in the EquivalenceClass data * structures as well. This is needed either if the parent * participates in some eclass joins (because we will want to consider @@ -1250,7 +1265,7 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, /* * Consider an append of partial unordered, unparameterized partial paths. */ - if (partial_subpaths_valid) + if (partial_subpaths_valid && rel->consider_parallel) { AppendPath *appendpath; ListCell *lc;