1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

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.
This commit is contained in:
Tom Lane
2012-08-12 16:01:26 -04:00
parent e76af54137
commit c1774d2c81
13 changed files with 390 additions and 89 deletions

View File

@ -147,6 +147,32 @@ add_paths_to_joinrel(PlannerInfo *root,
sjinfo->min_lefthand));
}
/*
* 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.