diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-08-12 16:01:26 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-08-12 16:01:26 -0400 |
commit | c1774d2c8193a322706f681dd984ac439d3a9dbb (patch) | |
tree | 85fd93fd7dfd6c71bd7236d2dba573fb9f4c51b6 /src/backend/optimizer/path/joinpath.c | |
parent | e76af54137c051cafcb1e39f68383a31d1d55ff6 (diff) |
More fixes for planner's handling of LATERAL.
Re-allow subquery pullup for LATERAL subqueries, except when the subquery
is below an outer join and contains lateral references to relations outside
that outer join. If we pull up in such a case, we risk introducing lateral
cross-references into outer joins' ON quals, which is something the code is
entirely unprepared to cope with right now; and I'm not sure it'll ever be
worth coping with.
Support lateral refs in VALUES (this seems to be the only additional path
type that needs such support as a consequence of re-allowing subquery
pullup).
Put in a slightly hacky fix for joinpath.c's refusal to consider
parameterized join paths even when there cannot be any unparameterized
ones. This was causing "could not devise a query plan for the given query"
failures in queries involving more than two FROM items.
Put in an even more hacky fix for distribute_qual_to_rels() being unhappy
with join quals that contain references to rels outside their syntactic
scope; which is to say, disable that test altogether. Need to think about
how to preserve some sort of debugging cross-check here, while not
expending more cycles than befits a debugging cross-check.
Diffstat (limited to 'src/backend/optimizer/path/joinpath.c')
-rw-r--r-- | src/backend/optimizer/path/joinpath.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c index fe0e4d7c201..f54c3931ce4 100644 --- a/src/backend/optimizer/path/joinpath.c +++ b/src/backend/optimizer/path/joinpath.c @@ -148,6 +148,32 @@ add_paths_to_joinrel(PlannerInfo *root, } /* + * However, when a LATERAL subquery is involved, we have to be a bit + * laxer, because there may simply not be any paths for the joinrel that + * aren't parameterized by whatever the subquery is parameterized by. + * Hence, add to param_source_rels anything that is in the minimum + * parameterization of either input (and not in the other input). + * + * XXX need a more principled way of determining minimum parameterization. + */ + if (outerrel->cheapest_total_path == NULL) + { + Path *cheapest = (Path *) linitial(outerrel->cheapest_parameterized_paths); + + param_source_rels = bms_join(param_source_rels, + bms_difference(PATH_REQ_OUTER(cheapest), + innerrel->relids)); + } + if (innerrel->cheapest_total_path == NULL) + { + Path *cheapest = (Path *) linitial(innerrel->cheapest_parameterized_paths); + + param_source_rels = bms_join(param_source_rels, + bms_difference(PATH_REQ_OUTER(cheapest), + outerrel->relids)); + } + + /* * 1. Consider mergejoin paths where both relations must be explicitly * sorted. Skip this if we can't mergejoin. */ |