Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66bb44c

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 parent2b47146 commit66bb44c

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
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+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.67.2.1 2005/01/23 02:25:25 tgl Exp $
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_join_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+
JoinTypejointype,
632638
List*outer_pathkeys)
633639
{
640+
if (jointype==JOIN_FULL||jointype==JOIN_RIGHT)
641+
returnNIL;
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
ScanDirectionscandir);
113113
externList*build_join_pathkeys(Query*root,
114114
RelOptInfo*joinrel,
115+
JoinTypejointype,
115116
List*outer_pathkeys);
116117
externList*make_pathkeys_for_sortclauses(List*sortclauses,
117118
List*tlist);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp