Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit109a4a6

Browse files
committed
Be a little smarter in group_clauses_by_indexkey_for_join: detect cases
where a joinclause is redundant with a restriction clause. Original codingbelieved this was impossible and didn't need to be checked for, but thatwas a thinko ...
1 parent4222491 commit109a4a6

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

‎src/backend/optimizer/path/indxpath.c

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.149 2003/11/29 19:51:50 pgsql Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.150 2003/12/18 00:22:12 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -600,14 +600,43 @@ group_clauses_by_indexkey_for_join(Query *root,
600600
{
601601
OidcurClass=classes[0];
602602
FastListclausegroup;
603+
intnumsources;
603604
List*i;
604605

605606
FastListInit(&clausegroup);
606607

608+
/*
609+
* We can always use plain restriction clauses for the rel. We scan
610+
* these first because we want them first in the clausegroup list
611+
* for the convenience of remove_redundant_join_clauses, which can
612+
* never remove non-join clauses and hence won't be able to get rid
613+
* of a non-join clause if it appears after a join clause it is
614+
* redundant with.
615+
*/
616+
foreach(i,rel->baserestrictinfo)
617+
{
618+
RestrictInfo*rinfo= (RestrictInfo*)lfirst(i);
619+
620+
/* Can't use pushed-down clauses in outer join */
621+
if (isouterjoin&&rinfo->ispusheddown)
622+
continue;
623+
624+
if (match_clause_to_indexcol(rel,
625+
index,
626+
indexcol,
627+
curClass,
628+
rinfo->clause))
629+
FastAppend(&clausegroup,rinfo);
630+
}
631+
632+
/* found anything in base restrict list? */
633+
numsources= (FastListValue(&clausegroup)!=NIL) ?1 :0;
634+
607635
/* Look for joinclauses that are usable with given outer_relids */
608636
foreach(i,rel->joininfo)
609637
{
610638
JoinInfo*joininfo= (JoinInfo*)lfirst(i);
639+
booljfoundhere= false;
611640
List*j;
612641

613642
if (!bms_is_subset(joininfo->unjoined_relids,outer_relids))
@@ -628,20 +657,21 @@ group_clauses_by_indexkey_for_join(Query *root,
628657
rinfo->clause))
629658
{
630659
FastAppend(&clausegroup,rinfo);
631-
jfound= true;
660+
if (!jfoundhere)
661+
{
662+
jfoundhere= true;
663+
jfound= true;
664+
numsources++;
665+
}
632666
}
633667
}
634668
}
635669

636670
/*
637-
* If we found join clauses in more than one joininfo list, we may
638-
* now have clauses that are known redundant. Get rid of 'em.
639-
* (There is no point in looking at restriction clauses, because
640-
* remove_redundant_join_clauses will never think they are
641-
* redundant, so we do this before adding restriction clauses to
642-
* the clause group.)
671+
* If we found clauses in more than one list, we may now have clauses
672+
* that are known redundant. Get rid of 'em.
643673
*/
644-
if (FastListValue(&clausegroup)!=NIL)
674+
if (numsources>1)
645675
{
646676
List*nl;
647677

@@ -651,23 +681,6 @@ group_clauses_by_indexkey_for_join(Query *root,
651681
FastListFromList(&clausegroup,nl);
652682
}
653683

654-
/* We can also use plain restriction clauses for the rel */
655-
foreach(i,rel->baserestrictinfo)
656-
{
657-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(i);
658-
659-
/* Can't use pushed-down clauses in outer join */
660-
if (isouterjoin&&rinfo->ispusheddown)
661-
continue;
662-
663-
if (match_clause_to_indexcol(rel,
664-
index,
665-
indexcol,
666-
curClass,
667-
rinfo->clause))
668-
FastAppend(&clausegroup,rinfo);
669-
}
670-
671684
/*
672685
* If no clauses match this key, we're done; we don't want to look
673686
* at keys to its right.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp