aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/relnode.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2016-06-09 12:40:23 -0400
committerRobert Haas <rhaas@postgresql.org>2016-06-09 12:43:36 -0400
commitb12fd41c695b43c76b0a9a4d19ba43b05536440c (patch)
tree966a7ca8b9c268b70f38257a56aeccaa25fd82b2 /src/backend/optimizer/util/relnode.c
parente7bcd983f56136a9580076b60d5c19eb2fd83301 (diff)
downloadpostgresql-b12fd41c695b43c76b0a9a4d19ba43b05536440c.tar.gz
postgresql-b12fd41c695b43c76b0a9a4d19ba43b05536440c.zip
Don't generate parallel paths for rels with parallel-restricted outputs.
Such paths are unsafe. To make it cheaper to detect when this case applies, track whether a relation's default PathTarget contains any non-Vars. In most cases, the answer will be no, which enables us to determine cheaply that the target list for a proposed path is parallel-safe. However, subquery pull-up can create cases that require us to inspect the target list more carefully. Amit Kapila, reviewed by me.
Diffstat (limited to 'src/backend/optimizer/util/relnode.c')
-rw-r--r--src/backend/optimizer/util/relnode.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
index e2ebf479296..2def06dd922 100644
--- a/src/backend/optimizer/util/relnode.c
+++ b/src/backend/optimizer/util/relnode.c
@@ -109,6 +109,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptKind reloptkind)
rel->consider_parallel = false; /* might get changed later */
rel->rel_parallel_workers = -1; /* set up in GetRelationInfo */
rel->reltarget = create_empty_pathtarget();
+ rel->reltarget_has_non_vars = false;
rel->pathlist = NIL;
rel->ppilist = NIL;
rel->partial_pathlist = NIL;
@@ -396,6 +397,7 @@ build_join_rel(PlannerInfo *root,
joinrel->consider_param_startup = false;
joinrel->consider_parallel = false;
joinrel->reltarget = create_empty_pathtarget();
+ joinrel->reltarget_has_non_vars = false;
joinrel->pathlist = NIL;
joinrel->ppilist = NIL;
joinrel->partial_pathlist = NIL;
@@ -506,8 +508,8 @@ build_join_rel(PlannerInfo *root,
* Set the consider_parallel flag if this joinrel could potentially be
* scanned within a parallel worker. If this flag is false for either
* inner_rel or outer_rel, then it must be false for the joinrel also.
- * Even if both are true, there might be parallel-restricted quals at our
- * level.
+ * Even if both are true, there might be parallel-restricted expressions
+ * in the targetlist or quals.
*
* Note that if there are more than two rels in this relation, they could
* be divided between inner_rel and outer_rel in any arbitrary way. We
@@ -517,7 +519,9 @@ build_join_rel(PlannerInfo *root,
* here.
*/
if (inner_rel->consider_parallel && outer_rel->consider_parallel &&
- !has_parallel_hazard((Node *) restrictlist, false))
+ !has_parallel_hazard((Node *) restrictlist, false) &&
+ !(joinrel->reltarget_has_non_vars &&
+ has_parallel_hazard((Node *) joinrel->reltarget->exprs, false)))
joinrel->consider_parallel = true;
/*