Skip to content

Commit 280de29

Browse files
committed
In cost_mergejoin, the early-exit effect should not apply to the
outer side of an outer join. Per andrew@supernews.
1 parent 503edbd commit 280de29

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
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)
917917
rescanratio = 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
{
931932
firstclause = (RestrictInfo *) linitial(mergeclauses);
932933
if (firstclause->left_mergescansel < 0) /* not computed yet? */
@@ -946,10 +947,14 @@ cost_mergejoin(MergePath *path, Query *root)
946947
outerscansel = firstclause->right_mergescansel;
947948
innerscansel = 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
}
950955
else
951956
{
952-
/* cope with clauseless mergejoin */
957+
/* cope with clauseless or full mergejoin */
953958
outerscansel = innerscansel = 1.0;
954959
}
955960

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy