41
41
* Portions Copyright (c) 1994, Regents of the University of California
42
42
*
43
43
* IDENTIFICATION
44
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.67 2001/02/15 17:46:40 tgl Exp $
44
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.68 2001/02/16 00:03:07 tgl Exp $
45
45
*
46
46
*-------------------------------------------------------------------------
47
47
*/
@@ -837,11 +837,12 @@ void
837
837
set_joinrel_size_estimates (Query * root , RelOptInfo * rel ,
838
838
RelOptInfo * outer_rel ,
839
839
RelOptInfo * inner_rel ,
840
+ JoinType jointype ,
840
841
List * restrictlist )
841
842
{
842
843
double temp ;
843
844
844
- /* cartesian product */
845
+ /* Start with the Cartesian product */
845
846
temp = outer_rel -> rows * inner_rel -> rows ;
846
847
847
848
/*
@@ -854,13 +855,43 @@ set_joinrel_size_estimates(Query *root, RelOptInfo *rel,
854
855
restrictlist ,
855
856
0 );
856
857
858
+ /*
859
+ * If we are doing an outer join, take that into account: the output
860
+ * must be at least as large as the non-nullable input. (Is there any
861
+ * chance of being even smarter?)
862
+ */
863
+ switch (jointype )
864
+ {
865
+ case JOIN_INNER :
866
+ break ;
867
+ case JOIN_LEFT :
868
+ if (temp < outer_rel -> rows )
869
+ temp = outer_rel -> rows ;
870
+ break ;
871
+ case JOIN_RIGHT :
872
+ if (temp < inner_rel -> rows )
873
+ temp = inner_rel -> rows ;
874
+ break ;
875
+ case JOIN_FULL :
876
+ if (temp < outer_rel -> rows )
877
+ temp = outer_rel -> rows ;
878
+ if (temp < inner_rel -> rows )
879
+ temp = inner_rel -> rows ;
880
+ break ;
881
+ default :
882
+ elog (ERROR , "set_joinrel_size_estimates: unsupported join type %d" ,
883
+ (int ) jointype );
884
+ break ;
885
+ }
886
+
857
887
/*
858
888
* Force estimate to be at least one row, to make explain output look
859
889
* better and to avoid possible divide-by-zero when interpolating
860
890
* cost.
861
891
*/
862
892
if (temp < 1.0 )
863
893
temp = 1.0 ;
894
+
864
895
rel -> rows = temp ;
865
896
866
897
/*
0 commit comments