summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-07-31 19:26:33 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2015-07-31 19:26:33 -0400
commita4df781c9037584d66a6f04b0b010a5bab0b509b (patch)
tree12d883e53004ef3a0350c7182dd228a8fa6409d6 /src/backend/optimizer
parentcaae9f764699e44e2e95394b90f48d4429b8ea3f (diff)
Fix an oversight in checking whether a join with LATERAL refs is legal.
In many cases, we can implement a semijoin as a plain innerjoin by first passing the righthand-side relation through a unique-ification step. However, one of the cases where this does NOT work is where the RHS has a LATERAL reference to the LHS; that makes the RHS dependent on the LHS so that unique-ification is meaningless. joinpath.c understood this, and so would not generate any join paths of this kind ... but join_is_legal neglected to check for the case, so it would think that we could do it. The upshot would be a "could not devise a query plan for the given query" failure once we had failed to generate any join paths at all for the bogus join pair. Back-patch to 9.3 where LATERAL was added.
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r--src/backend/optimizer/path/joinrels.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/optimizer/path/joinrels.c b/src/backend/optimizer/path/joinrels.c
index fd6a4f19b1d..33a8b2d22e7 100644
--- a/src/backend/optimizer/path/joinrels.c
+++ b/src/backend/optimizer/path/joinrels.c
@@ -536,7 +536,9 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
if (!bms_is_subset(ljinfo->lateral_lhs, rel1->relids))
return false; /* rel1 can't compute the required parameter */
if (match_sjinfo &&
- (reversed || match_sjinfo->jointype == JOIN_FULL))
+ (reversed ||
+ unique_ified ||
+ match_sjinfo->jointype == JOIN_FULL))
return false; /* not implementable as nestloop */
}
if (bms_is_subset(ljinfo->lateral_rhs, rel1->relids) &&
@@ -549,7 +551,9 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
if (!bms_is_subset(ljinfo->lateral_lhs, rel2->relids))
return false; /* rel2 can't compute the required parameter */
if (match_sjinfo &&
- (!reversed || match_sjinfo->jointype == JOIN_FULL))
+ (!reversed ||
+ unique_ified ||
+ match_sjinfo->jointype == JOIN_FULL))
return false; /* not implementable as nestloop */
}
}