4949 * Portions Copyright (c) 1994, Regents of the University of California
5050 *
5151 * 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 $
5353 *
5454 *-------------------------------------------------------------------------
5555 */
@@ -917,16 +917,17 @@ cost_mergejoin(MergePath *path, Query *root)
917917rescanratio = 1.0 + (rescannedtuples /inner_path_rows );
918918
919919/*
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.
924925 *
925926 * Since this calculation is somewhat expensive, and will be the same for
926927 * all mergejoin paths associated with the merge clause, we cache the
927928 * results in the RestrictInfo node.
928929 */
929- if (mergeclauses )
930+ if (mergeclauses && path -> jpath . jointype != JOIN_FULL )
930931{
931932firstclause = (RestrictInfo * )linitial (mergeclauses );
932933if (firstclause -> left_mergescansel < 0 )/* not computed yet? */
@@ -946,10 +947,14 @@ cost_mergejoin(MergePath *path, Query *root)
946947outerscansel = firstclause -> right_mergescansel ;
947948innerscansel = firstclause -> left_mergescansel ;
948949}
950+ if (path -> jpath .jointype == JOIN_LEFT )
951+ outerscansel = 1.0 ;
952+ else if (path -> jpath .jointype == JOIN_RIGHT )
953+ innerscansel = 1.0 ;
949954}
950955else
951956{
952- /* cope with clauseless mergejoin */
957+ /* cope with clauselessor full mergejoin */
953958outerscansel = innerscansel = 1.0 ;
954959}
955960