Be a little smarter in group_clauses_by_indexkey_for_join: detect cases
where a joinclause is redundant with a restriction clause. Original coding believed this was impossible and didn't need to be checked for, but that was a thinko ...
This commit is contained in:
parent
422249120d
commit
109a4a603f
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.149 2003/11/29 19:51:50 pgsql Exp $
|
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.150 2003/12/18 00:22:12 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -600,14 +600,43 @@ group_clauses_by_indexkey_for_join(Query *root,
|
|||||||
{
|
{
|
||||||
Oid curClass = classes[0];
|
Oid curClass = classes[0];
|
||||||
FastList clausegroup;
|
FastList clausegroup;
|
||||||
|
int numsources;
|
||||||
List *i;
|
List *i;
|
||||||
|
|
||||||
FastListInit(&clausegroup);
|
FastListInit(&clausegroup);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We can always use plain restriction clauses for the rel. We scan
|
||||||
|
* these first because we want them first in the clausegroup list
|
||||||
|
* for the convenience of remove_redundant_join_clauses, which can
|
||||||
|
* never remove non-join clauses and hence won't be able to get rid
|
||||||
|
* of a non-join clause if it appears after a join clause it is
|
||||||
|
* redundant with.
|
||||||
|
*/
|
||||||
|
foreach(i, rel->baserestrictinfo)
|
||||||
|
{
|
||||||
|
RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
|
||||||
|
|
||||||
|
/* Can't use pushed-down clauses in outer join */
|
||||||
|
if (isouterjoin && rinfo->ispusheddown)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (match_clause_to_indexcol(rel,
|
||||||
|
index,
|
||||||
|
indexcol,
|
||||||
|
curClass,
|
||||||
|
rinfo->clause))
|
||||||
|
FastAppend(&clausegroup, rinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* found anything in base restrict list? */
|
||||||
|
numsources = (FastListValue(&clausegroup) != NIL) ? 1 : 0;
|
||||||
|
|
||||||
/* Look for joinclauses that are usable with given outer_relids */
|
/* Look for joinclauses that are usable with given outer_relids */
|
||||||
foreach(i, rel->joininfo)
|
foreach(i, rel->joininfo)
|
||||||
{
|
{
|
||||||
JoinInfo *joininfo = (JoinInfo *) lfirst(i);
|
JoinInfo *joininfo = (JoinInfo *) lfirst(i);
|
||||||
|
bool jfoundhere = false;
|
||||||
List *j;
|
List *j;
|
||||||
|
|
||||||
if (!bms_is_subset(joininfo->unjoined_relids, outer_relids))
|
if (!bms_is_subset(joininfo->unjoined_relids, outer_relids))
|
||||||
@ -628,20 +657,21 @@ group_clauses_by_indexkey_for_join(Query *root,
|
|||||||
rinfo->clause))
|
rinfo->clause))
|
||||||
{
|
{
|
||||||
FastAppend(&clausegroup, rinfo);
|
FastAppend(&clausegroup, rinfo);
|
||||||
jfound = true;
|
if (!jfoundhere)
|
||||||
|
{
|
||||||
|
jfoundhere = true;
|
||||||
|
jfound = true;
|
||||||
|
numsources++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we found join clauses in more than one joininfo list, we may
|
* If we found clauses in more than one list, we may now have clauses
|
||||||
* now have clauses that are known redundant. Get rid of 'em.
|
* that are known redundant. Get rid of 'em.
|
||||||
* (There is no point in looking at restriction clauses, because
|
|
||||||
* remove_redundant_join_clauses will never think they are
|
|
||||||
* redundant, so we do this before adding restriction clauses to
|
|
||||||
* the clause group.)
|
|
||||||
*/
|
*/
|
||||||
if (FastListValue(&clausegroup) != NIL)
|
if (numsources > 1)
|
||||||
{
|
{
|
||||||
List *nl;
|
List *nl;
|
||||||
|
|
||||||
@ -651,23 +681,6 @@ group_clauses_by_indexkey_for_join(Query *root,
|
|||||||
FastListFromList(&clausegroup, nl);
|
FastListFromList(&clausegroup, nl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We can also use plain restriction clauses for the rel */
|
|
||||||
foreach(i, rel->baserestrictinfo)
|
|
||||||
{
|
|
||||||
RestrictInfo *rinfo = (RestrictInfo *) lfirst(i);
|
|
||||||
|
|
||||||
/* Can't use pushed-down clauses in outer join */
|
|
||||||
if (isouterjoin && rinfo->ispusheddown)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (match_clause_to_indexcol(rel,
|
|
||||||
index,
|
|
||||||
indexcol,
|
|
||||||
curClass,
|
|
||||||
rinfo->clause))
|
|
||||||
FastAppend(&clausegroup, rinfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If no clauses match this key, we're done; we don't want to look
|
* If no clauses match this key, we're done; we don't want to look
|
||||||
* at keys to its right.
|
* at keys to its right.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user