49
49
* Portions Copyright (c) 1994, Regents of the University of California
50
50
*
51
51
* IDENTIFICATION
52
- * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.140 2005/03/27 23:53:02 tgl Exp $
52
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.141 2005/04/04 01:43:12 tgl Exp $
53
53
*
54
54
*-------------------------------------------------------------------------
55
55
*/
@@ -917,16 +917,17 @@ cost_mergejoin(MergePath *path, Query *root)
917
917
rescanratio = 1.0 + (rescannedtuples / inner_path_rows );
918
918
919
919
/*
920
- * A merge join will stop as soon as it exhausts either input stream.
921
- * Estimate fraction of the left and right inputs that will actually
922
- * need to be scanned. We use only the first (most significant) merge
923
- * clause for this purpose.
920
+ * A merge join will stop as soon as it exhausts either input stream
921
+ * (unless it's an outer join, in which case the outer side has to be
922
+ * scanned all the way anyway). Estimate fraction of the left and right
923
+ * inputs that will actually need to be scanned. We use only the first
924
+ * (most significant) merge clause for this purpose.
924
925
*
925
926
* Since this calculation is somewhat expensive, and will be the same for
926
927
* all mergejoin paths associated with the merge clause, we cache the
927
928
* results in the RestrictInfo node.
928
929
*/
929
- if (mergeclauses )
930
+ if (mergeclauses && path -> jpath . jointype != JOIN_FULL )
930
931
{
931
932
firstclause = (RestrictInfo * ) linitial (mergeclauses );
932
933
if (firstclause -> left_mergescansel < 0 ) /* not computed yet? */
@@ -946,10 +947,14 @@ cost_mergejoin(MergePath *path, Query *root)
946
947
outerscansel = firstclause -> right_mergescansel ;
947
948
innerscansel = firstclause -> left_mergescansel ;
948
949
}
950
+ if (path -> jpath .jointype == JOIN_LEFT )
951
+ outerscansel = 1.0 ;
952
+ else if (path -> jpath .jointype == JOIN_RIGHT )
953
+ innerscansel = 1.0 ;
949
954
}
950
955
else
951
956
{
952
- /* cope with clauseless mergejoin */
957
+ /* cope with clauseless or full mergejoin */
953
958
outerscansel = innerscansel = 1.0 ;
954
959
}
955
960
0 commit comments