]> granicus.if.org Git - postgresql/commitdiff
The result of a FULL or RIGHT join can't be assumed to be sorted by the
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Jan 2005 02:23:30 +0000 (02:23 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 23 Jan 2005 02:23:30 +0000 (02:23 +0000)
left input's sorting, because null rows may be inserted at various points.
Per report from Ferenc Lutischá¸n.

src/backend/optimizer/path/joinpath.c
src/backend/optimizer/path/pathkeys.c
src/include/optimizer/paths.h

index 956dd991cd6626b6df4736ae617afcc1380f838f..b1a25505b5e2019db39187107f0c0dd4f6759c98 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.82.2.1 2004/04/06 18:46:25 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.82.2.2 2005/01/23 02:23:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -271,7 +271,8 @@ sort_inner_and_outer(Query *root,
                                                                                                   cur_mergeclauses,
                                                                                                   innerrel);
                /* Build pathkeys representing output sort order. */
-               merge_pathkeys = build_join_pathkeys(root, joinrel, outerkeys);
+               merge_pathkeys = build_join_pathkeys(root, joinrel, jointype,
+                                                                                        outerkeys);
 
                /*
                 * And now we can make the path.
@@ -431,7 +432,7 @@ match_unsorted_outer(Query *root,
                 * as a nestloop, and even if some of the mergeclauses are
                 * implemented by qpquals rather than as true mergeclauses):
                 */
-               merge_pathkeys = build_join_pathkeys(root, joinrel,
+               merge_pathkeys = build_join_pathkeys(root, joinrel, jointype,
                                                                                         outerpath->pathkeys);
 
                if (nestjoinOK)
index fd3f3ab18693d899e7be955c98780e81d5fdacfe..16a9a1c130c6d06f814b1cd32e96d8ea8444c621 100644 (file)
@@ -11,7 +11,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.53.4.1 2003/12/03 17:45:36 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.53.4.2 2005/01/23 02:23:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -861,7 +861,12 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
  *       vars they were joined with; furthermore, it doesn't matter what kind
  *       of join algorithm is actually used.
  *
+ *       EXCEPTION: in a FULL or RIGHT join, we cannot treat the result as
+ *       having the outer path's path keys, because null lefthand rows may be
+ *       inserted at random points.  It must be treated as unsorted.
+ *
  * 'joinrel' is the join relation that paths are being formed for
+ * 'jointype' is the join type (inner, left, full, etc)
  * 'outer_pathkeys' is the list of the current outer path's path keys
  *
  * Returns the list of new path keys.
@@ -869,8 +874,12 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
 List *
 build_join_pathkeys(Query *root,
                                        RelOptInfo *joinrel,
+                                       JoinType jointype,
                                        List *outer_pathkeys)
 {
+       if (jointype == JOIN_FULL || jointype == JOIN_RIGHT)
+               return NIL;
+
        /*
         * This used to be quite a complex bit of code, but now that all
         * pathkey sublists start out life canonicalized, we don't have to do
index 2a748975195b5ed07f77c9037977cc4fc0f8b341..bab33083d8e6c1040c622f6eac1f1b3f30ff344b 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: paths.h,v 1.69 2003/08/04 02:40:14 momjian Exp $
+ * $Id: paths.h,v 1.69.4.1 2005/01/23 02:23:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -109,6 +109,7 @@ extern List *build_subquery_pathkeys(Query *root, RelOptInfo *rel,
                                                Query *subquery);
 extern List *build_join_pathkeys(Query *root,
                                        RelOptInfo *joinrel,
+                                       JoinType jointype,
                                        List *outer_pathkeys);
 extern List *make_pathkeys_for_sortclauses(List *sortclauses,
                                                          List *tlist);