mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Suppress creation of backwardly-indexed paths for LATERAL join clauses.
Given a query such as SELECT * FROM foo JOIN LATERAL (SELECT foo.var1) ss(x) ON ss.x = foo.var2 the existence of the join clause "ss.x = foo.var2" encourages indxpath.c to build a parameterized path for foo using any index available for foo.var2. This is completely useless activity, though, since foo has got to be on the outside not the inside of any nestloop join with ss. It's reasonably inexpensive to add tests that prevent creation of such paths, so let's do that.
This commit is contained in:
@@ -1969,11 +1969,15 @@ mutate_eclass_expressions(PlannerInfo *root,
|
||||
* is no value in using more than one. (But it *is* worthwhile to create
|
||||
* a separate parameterized path for each one, since that leads to different
|
||||
* join orders.)
|
||||
*
|
||||
* The caller can pass a Relids set of rels we aren't interested in joining
|
||||
* to, so as to save the work of creating useless clauses.
|
||||
*/
|
||||
List *
|
||||
generate_implied_equalities_for_indexcol(PlannerInfo *root,
|
||||
IndexOptInfo *index,
|
||||
int indexcol)
|
||||
int indexcol,
|
||||
Relids prohibited_rels)
|
||||
{
|
||||
List *result = NIL;
|
||||
RelOptInfo *rel = index->rel;
|
||||
@@ -2050,6 +2054,10 @@ generate_implied_equalities_for_indexcol(PlannerInfo *root,
|
||||
bms_overlap(other_em->em_relids, rel->relids))
|
||||
continue;
|
||||
|
||||
/* Forget it if caller doesn't want joins to this rel */
|
||||
if (bms_overlap(other_em->em_relids, prohibited_rels))
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Also, if this is a child rel, avoid generating a useless join
|
||||
* to its parent rel.
|
||||
|
||||
Reference in New Issue
Block a user