1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

In cost_mergejoin, the early-exit effect should not apply to the

outer side of an outer join.  Per andrew@supernews.
This commit is contained in:
Tom Lane
2005-04-04 01:43:33 +00:00
parent 3ea32d7b1f
commit 5c5c797cb2

View File

@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.115.2.2 2004/04/06 18:46:25 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.115.2.3 2005/04/04 01:43:33 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -919,16 +919,17 @@ cost_mergejoin(MergePath *path, Query *root)
rescanratio = 1.0 + (rescannedtuples / inner_path_rows); rescanratio = 1.0 + (rescannedtuples / inner_path_rows);
/* /*
* A merge join will stop as soon as it exhausts either input stream. * A merge join will stop as soon as it exhausts either input stream
* Estimate fraction of the left and right inputs that will actually * (unless it's an outer join, in which case the outer side has to be
* need to be scanned. We use only the first (most significant) merge * scanned all the way anyway). Estimate fraction of the left and right
* clause for this purpose. * inputs that will actually need to be scanned. We use only the first
* (most significant) merge clause for this purpose.
* *
* Since this calculation is somewhat expensive, and will be the same for * Since this calculation is somewhat expensive, and will be the same for
* all mergejoin paths associated with the merge clause, we cache the * all mergejoin paths associated with the merge clause, we cache the
* results in the RestrictInfo node. * results in the RestrictInfo node.
*/ */
if (mergeclauses) if (mergeclauses && path->jpath.jointype != JOIN_FULL)
{ {
firstclause = (RestrictInfo *) lfirst(mergeclauses); firstclause = (RestrictInfo *) lfirst(mergeclauses);
if (firstclause->left_mergescansel < 0) /* not computed yet? */ if (firstclause->left_mergescansel < 0) /* not computed yet? */
@ -948,10 +949,14 @@ cost_mergejoin(MergePath *path, Query *root)
outerscansel = firstclause->right_mergescansel; outerscansel = firstclause->right_mergescansel;
innerscansel = firstclause->left_mergescansel; innerscansel = firstclause->left_mergescansel;
} }
if (path->jpath.jointype == JOIN_LEFT)
outerscansel = 1.0;
else if (path->jpath.jointype == JOIN_RIGHT)
innerscansel = 1.0;
} }
else else
{ {
/* cope with clauseless mergejoin */ /* cope with clauseless or full mergejoin */
outerscansel = innerscansel = 1.0; outerscansel = innerscansel = 1.0;
} }