9
9
*
10
10
*
11
11
* 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 $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -600,14 +600,43 @@ group_clauses_by_indexkey_for_join(Query *root,
600
600
{
601
601
Oid curClass = classes [0 ];
602
602
FastList clausegroup ;
603
+ int numsources ;
603
604
List * i ;
604
605
605
606
FastListInit (& clausegroup );
606
607
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
+
607
635
/* Look for joinclauses that are usable with given outer_relids */
608
636
foreach (i , rel -> joininfo )
609
637
{
610
638
JoinInfo * joininfo = (JoinInfo * ) lfirst (i );
639
+ bool jfoundhere = false;
611
640
List * j ;
612
641
613
642
if (!bms_is_subset (joininfo -> unjoined_relids , outer_relids ))
@@ -628,20 +657,21 @@ group_clauses_by_indexkey_for_join(Query *root,
628
657
rinfo -> clause ))
629
658
{
630
659
FastAppend (& clausegroup , rinfo );
631
- jfound = true;
660
+ if (!jfoundhere )
661
+ {
662
+ jfoundhere = true;
663
+ jfound = true;
664
+ numsources ++ ;
665
+ }
632
666
}
633
667
}
634
668
}
635
669
636
670
/*
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.
643
673
*/
644
- if (FastListValue ( & clausegroup ) != NIL )
674
+ if (numsources > 1 )
645
675
{
646
676
List * nl ;
647
677
@@ -651,23 +681,6 @@ group_clauses_by_indexkey_for_join(Query *root,
651
681
FastListFromList (& clausegroup , nl );
652
682
}
653
683
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
-
671
684
/*
672
685
* If no clauses match this key, we're done; we don't want to look
673
686
* at keys to its right.
0 commit comments