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

Commit75cccd0

Browse files
committed
pathkeys fixes
1 parent0ff2733 commit75cccd0

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

‎src/backend/nodes/print.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.22 1999/02/13 23:16:00 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.23 1999/02/20 19:02:40 momjian Exp $
1111
*
1212
* HISTORY
1313
* AUTHORDATEMAJOR EVENT
@@ -213,20 +213,28 @@ print_expr(Node *expr, List *rtable)
213213

214214
/*
215215
* print_pathkeys -
216-
*temporary here. where is keyslist oflists
216+
*pathkeys list oflist ofVar's
217217
*/
218218
void
219219
print_pathkeys(List*pathkeys,List*rtable)
220220
{
221-
List*k;
221+
List*i,*k;
222222

223223
printf("(");
224-
foreach(k,pathkeys)
224+
foreach(i,pathkeys)
225225
{
226-
Node*var=lfirst((List*)lfirst(k));
226+
Listpathkey=lfirst(i));
227227

228-
print_expr(var,rtable);
229-
if (lnext(k))
228+
printf("(");
229+
foreach(k,pathkey)
230+
{
231+
Node*var=lfirst(k);
232+
print_expr(var,rtable);
233+
if (lnext(k))
234+
printf(", ");
235+
}
236+
printf(") ");
237+
if (lnext(i))
230238
printf(", ");
231239
}
232240
printf(")\n");

‎src/backend/optimizer/path/pathkeys.c

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.4 1999/02/2018:01:01 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.5 1999/02/2019:02:41 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -54,7 +54,19 @@ static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
5454
*{ {tab1.col1, tab2.col1} }. This allows future joins to use either Var
5555
*as a pre-sorted key to prevent Mergejoins from having to re-sort the Path.
5656
*They are equal, so they are both primary sort keys. This is why pathkeys
57-
*is a List of Lists. -- bjm
57+
*is a List of Lists.
58+
*
59+
*For multi-key sorts, if the outer is sorted by a multi-key index, the
60+
*multi-key index remains after the join. If the inner has a multi-key
61+
*sort, only the primary key of the inner is added to the result.
62+
*Mergejoins only join on the primary key. Currently, non-primary keys
63+
*in the pathkeys List are of limited value.
64+
*
65+
*HashJoin has similar functionality. NestJoin does not perform sorting,
66+
*and allows non-equajoins, so it does not allow useful pathkeys.
67+
*
68+
*-- bjm
69+
*
5870
*/
5971

6072
/****************************************************************************
@@ -92,17 +104,21 @@ static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
92104
*/
93105
List*
94106
order_joinkeys_by_pathkeys(List*pathkeys,
95-
List*joinkeys,
96-
List*joinclauses,
97-
intouter_or_inner,
98-
List**matchedJoinClausesPtr)
107+
List*joinkeys,
108+
List*joinclauses,
109+
intouter_or_inner,
110+
List**matchedJoinClausesPtr)
99111
{
100112
List*matched_joinkeys=NIL;
101113
List*matched_joinclauses=NIL;
102114
List*pathkey=NIL;
103115
List*i=NIL;
104116
intmatched_joinkey_index=-1;
105117

118+
/*
119+
*Reorder the joinkeys by picking out one that matches each pathkey,
120+
*and create a new joinkey/joinclause list in pathkey order
121+
*/
106122
foreach(i,pathkeys)
107123
{
108124
pathkey=lfirst(i);
@@ -118,10 +134,18 @@ order_joinkeys_by_pathkeys(List *pathkeys,
118134
matched_joinclauses=lappend(matched_joinclauses,joinclause);
119135
}
120136
else
121-
{
137+
/*A pathkey could not be matched. */
138+
break;
139+
}
140+
141+
/*
142+
*Did we fail to match all the joinkeys?
143+
*Extra pathkeys are no problem.
144+
*/
145+
if (length(joinkeys)!=length(matched_joinkeys))
146+
{
122147
*matchedJoinClausesPtr=NIL;
123148
returnNIL;
124-
}
125149
}
126150

127151
*matchedJoinClausesPtr=matched_joinclauses;
@@ -133,6 +157,8 @@ order_joinkeys_by_pathkeys(List *pathkeys,
133157
* match_pathkey_joinkeys
134158
* Returns the 0-based index into 'joinkeys' of the first joinkey whose
135159
* outer or inner subkey matches any subkey of 'pathkey'.
160+
*
161+
*All these keys are equivalent, so any of them can match. See above.
136162
*/
137163
staticint
138164
match_pathkey_joinkeys(List*pathkey,
@@ -141,8 +167,7 @@ match_pathkey_joinkeys(List *pathkey,
141167
{
142168
Var*path_subkey;
143169
intpos;
144-
List*i=NIL;
145-
List*x=NIL;
170+
List*i,*x;
146171
JoinKey*jk;
147172

148173
foreach(i,pathkey)
@@ -152,8 +177,7 @@ match_pathkey_joinkeys(List *pathkey,
152177
foreach(x,joinkeys)
153178
{
154179
jk= (JoinKey*)lfirst(x);
155-
if (var_equal(path_subkey,
156-
extract_join_key(jk,outer_or_inner)))
180+
if (var_equal(path_subkey,extract_join_key(jk,outer_or_inner)))
157181
returnpos;
158182
pos++;
159183
}

‎src/backend/optimizer/util/pathnode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.38 1999/02/2018:01:02 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.39 1999/02/2019:02:42 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -205,7 +205,7 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
205205
{
206206
/*
207207
* Replace pathkeys that match exactly, {{1,2}}, {{1,2}}
208-
* Replace pathkeys {{1,2}}with {{1,2,3}}} if the latter is not
208+
* Replace pathkeys {{1,2}}with {{1,2,3}}} if the latter is not
209209
* more expensive and replace unordered path with ordered
210210
* path if it is not more expensive. Favor sorted keys
211211
* over unsorted keys in the same way.

‎src/include/nodes/relation.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: relation.h,v 1.27 1999/02/2016:28:20 momjian Exp $
9+
* $Id: relation.h,v 1.28 1999/02/2019:02:43 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -142,8 +142,7 @@ typedef struct Path
142142

143143
PathOrder*pathorder;
144144

145-
List*pathkeys;/*
146-
* This is a List of List of Var nodes.
145+
List*pathkeys;/* This is a List of List of Var nodes.
147146
* See the top of optimizer/path/pathkeys.c
148147
* for more information.
149148
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp