Commit e5170860 authored by Tom Lane's avatar Tom Lane

Support FULL JOIN with no join clauses, such as X FULL JOIN Y ON TRUE.

That particular corner case is not exactly compelling, but given 7.4's
ability to discard redundant join clauses, it is possible for the situation
to arise from queries that are not so obviously silly.  Per bug report
of 6-Apr-04.
parent 2098ec6e
......@@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.125 2004/02/17 00:52:53 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.126 2004/04/06 18:46:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -918,6 +918,8 @@ cost_mergejoin(MergePath *path, Query *root)
* all mergejoin paths associated with the merge clause, we cache the
* results in the RestrictInfo node.
*/
if (mergeclauses)
{
firstclause = (RestrictInfo *) lfirst(mergeclauses);
if (firstclause->left_mergescansel < 0) /* not computed yet? */
mergejoinscansel(root, (Node *) firstclause->clause,
......@@ -936,6 +938,12 @@ cost_mergejoin(MergePath *path, Query *root)
outerscansel = firstclause->right_mergescansel;
innerscansel = firstclause->left_mergescansel;
}
}
else
{
/* cope with clauseless mergejoin */
outerscansel = innerscansel = 1.0;
}
/* convert selectivity to row count; must scan at least one row */
outer_rows = clamp_row_est(outer_path_rows * outerscansel);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.85 2004/01/05 05:07:35 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.86 2004/04/06 18:46:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -489,9 +489,27 @@ match_unsorted_outer(Query *root,
outerpath->pathkeys,
mergeclause_list);
/* Done with this outer path if no chance for a mergejoin */
/*
* Done with this outer path if no chance for a mergejoin.
*
* Special corner case: for "x FULL JOIN y ON true", there will be
* no join clauses at all. Ordinarily we'd generate a clauseless
* nestloop path, but since mergejoin is our only join type that
* supports FULL JOIN, it's necessary to generate a clauseless
* mergejoin path instead.
*
* Unfortunately this can't easily be extended to handle the case
* where there are joinclauses but none of them use mergejoinable
* operators; nodeMergejoin.c can only do a full join correctly if
* all the joinclauses are mergeclauses.
*/
if (mergeclauses == NIL)
{
if (jointype == JOIN_FULL && restrictlist == NIL)
/* okay to try for mergejoin */ ;
else
continue;
}
if (useallclauses && length(mergeclauses) != length(mergeclause_list))
continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment