8000 The result of a FULL or RIGHT join can't be assumed to be sorted by the · larkly/postgres-docker@66bb44c · GitHub
[go: up one dir, main page]

Skip to content

Commit 66bb44c

Browse files
committed
The result of a FULL or RIGHT join can't be assumed to be sorted by the
left input's sorting, because null rows may be inserted at various points. Per report from Ferenc Lutischá¸n.
1 parent 2b47146 commit 66bb44c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/backend/optimizer/path/joinpath.c

Lines changed: 4 additions & 3 deletions
< 8000 td data-grid-cell-id="diff-2028b6a1be71407aac50b1da1e34ac4ba5bf0b6699b631b7aaf6a46dd72b8251-11-11-2" data-line-anchor="diff-2028b6a1be71407aac50b1da1e34ac4ba5bf0b6699b631b7aaf6a46dd72b8251R11" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.67.2.1 2005/01/23 02:25:25 tgl Exp $
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.67 2001/11/11 19:18:54 tgl Exp $
11
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -253,7 +253,8 @@ sort_inner_and_outer(Query *root,
253253
cur_mergeclauses,
254254
innerrel);
255255
/* Build pathkeys representing output sort order. */
256-
merge_pathkeys = build_join_pathkeys(root, joinrel, outerkeys);
256+
merge_pathkeys = build_join_pathkeys(root, joinrel, jointype,
257+
outerkeys);
257258

258259
/*
259260
* And now we can make the path. We only consider the cheapest-
@@ -371,7 +372,7 @@ match_unsorted_outer(Query *root,
371372
* as a nestloop, and even if some of the mergeclauses are
372373
* implemented by qpquals rather than as true mergeclauses):
373374
*/
374-
merge_pathkeys = build_jo 8000 in_pathkeys(root, joinrel,
375+
merge_pathkeys = build_join_pathkeys(root, joinrel, jointype,
375376
outerpath->pathkeys);
376377

377378
if (nestjoinOK)

src/backend/optimizer/path/pathkeys.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.36 2001/11/11 20:33:53 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.36.2.1 2005/01/23 02:25:30 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -621,16 +621,25 @@ find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno)
621621
* vars they were joined with; furthermore, it doesn't matter what kind
622622
* of join algorithm is actually used.
623623
*
624+
* EXCEPTION: in a FULL or RIGHT join, we cannot treat the result as
625+
* having the outer path's path keys, because null lefthand rows may be
626+
* inserted at random points. It must be treated as unsorted.
627+
*
624628
* 'joinrel' is the join relation that paths are being formed for
629+
* 'jointype' is the join type (inner, left, full, etc)
625630
* 'outer_pathkeys' is the list of the current outer path's path keys
626631
*
627632
* Returns the list of new path keys.
628633
*/
629634
List *
630635
build_join_pathkeys(Query *root,
631636
RelOptInfo *joinrel,
637+
JoinType jointype,
632638
List *outer_pathkeys)
633639
{
640+
if (jointype == JOIN_FULL 8000 || jointype == JOIN_RIGHT)
641+
return NIL;
642+
634643
/*
635644
* This used to be quite a complex bit of code, but now that all
636645
* pathkey sublists start out life canonicalized, we don't have to do

src/include/optimizer/paths.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: paths.h,v 1.59 2001/11/05 17:46:34 momjian Exp $
11+
* $Id: paths.h,v 1.59.2.1 2005/01/23 02:26:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -112,6 +112,7 @@ extern List *build_index_pathkeys(Query *root, RelOptInfo *rel,
112112
ScanDirection scandir);
113113
extern List *build_join_pathkeys(Query *root,
114114
RelOptInfo *joinrel,
115+
JoinType jointype,
115116
List *outer_pathkeys);
116117
extern List *make_pathkeys_for_sortclauses(List *sortclauses,
117118
List *tlist);

0 commit comments

Comments
 (0)
0