Skip to content

Commit 23c3024

Browse files
committed
pathkeys.c cleanup.
1 parent 9d19785 commit 23c3024

File tree

4 files changed

+48
-68
lines changed

4 files changed

+48
-68
lines changed

src/backend/nodes/print.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/nodes/print.c,v 1.23 1999/02/20 19:02:40 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.24 1999/02/21 01:55:01 momjian Exp $
1111
*
1212
* HISTORY
1313
* AUTHOR DATE MAJOR EVENT
@@ -223,7 +223,7 @@ print_pathkeys(List *pathkeys, List *rtable)
223223
printf("(");
224224
foreach(i, pathkeys)
225225
{
226-
List pathkey = lfirst(i));
226+
List pathkey = lfirst(i);
227227

228228
printf("(");
229229
foreach(k, pathkey)

src/backend/optimizer/path/joinpath.c

Lines changed: 9 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/optimizer/path/joinpath.c,v 1.30 1999/02/19 05:18:04 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.31 1999/02/21 01:55:02 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -309,11 +309,12 @@ match_unsorted_outer(RelOptInfo *joinrel,
309309
{
310310
List *jmkeys = xmergeinfo->jmethod.jmkeys;
311311

312-
matchedJoinKeys = order_joinkeys_by_pathkeys(outerpath->pathkeys,
313-
jmkeys,
314-
clauses,
315-
OUTER,
316-
&matchedJoinClauses);
312+
order_joinkeys_by_pathkeys(outerpath->pathkeys,
313+
jmkeys,
314+
clauses,
315+
OUTER,
316+
&matchedJoinKeys,
317+
&matchedJoinClauses);
317318
merge_pathkeys = new_join_pathkeys(outerpath->pathkeys,
318319
joinrel->targetlist, clauses);
319320
}
@@ -449,10 +450,11 @@ match_unsorted_inner(RelOptInfo *joinrel,
449450
{
450451
List *jmkeys = xmergeinfo->jmethod.jmkeys;
451452

452-
matchedJoinKeys = order_joinkeys_by_pathkeys(innerpath->pathkeys,
453+
order_joinkeys_by_pathkeys(innerpath->pathkeys,
453454
jmkeys,
454455
clauses,
455456
INNER,
457+
&matchedJoinKeys,
456458
&matchedJoinClauses);
457459
}
458460

src/backend/optimizer/path/pathkeys.c

Lines changed: 33 additions & 56 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.5 1999/02/20 19:02:41 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.6 1999/02/21 01:55:02 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,8 +27,6 @@
2727

2828
static int match_pathkey_joinkeys(List *pathkey, List *joinkeys,
2929
int outer_or_inner);
30-
static bool joinkeys_pathkeys_match(List *joinkeys, List *pathkey,
31-
int outer_or_inner);
3230
static List *new_join_pathkey(List *subkeys, List *considered_subkeys,
3331
List *join_rel_tlist, List *joinclauses);
3432
static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
@@ -94,27 +92,28 @@ static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
9492
* Returns the join keys and corresponding join clauses in a list if all
9593
* of the path keys were matched:
9694
* (
97-
* ( (outerkey0 innerkey0) ... (outerkeyN innerkeyN) )
95+
* ( (outerkey0 innerkey0) ... (outerkeyN or innerkeyN) )
9896
* ( clause0 ... clauseN )
9997
* )
10098
* and nil otherwise.
10199
*
102100
* Returns a list of matched join keys and a list of matched join clauses
103-
* in matchedJoinClausesPtr. - ay 11/94
101+
* in pointers if valid order can be found.
104102
*/
105-
List *
103+
bool
106104
order_joinkeys_by_pathkeys(List *pathkeys,
107105
List *joinkeys,
108106
List *joinclauses,
109107
int outer_or_inner,
108+
List **matchedJoinKeysPtr,
110109
List **matchedJoinClausesPtr)
111110
{
112111
List *matched_joinkeys = NIL;
113112
List *matched_joinclauses = NIL;
114113
List *pathkey = NIL;
115114
List *i = NIL;
116115
int matched_joinkey_index = -1;
117-
116+
int matched_keys = 0;
118117
/*
119118
* Reorder the joinkeys by picking out one that matches each pathkey,
120119
* and create a new joinkey/joinclause list in pathkey order
@@ -127,11 +126,19 @@ order_joinkeys_by_pathkeys(List *pathkeys,
127126

128127
if (matched_joinkey_index != -1)
129128
{
130-
List *xjoinkey = nth(matched_joinkey_index, joinkeys);
131-
List *joinclause = nth(matched_joinkey_index, joinclauses);
132-
133-
matched_joinkeys = lappend(matched_joinkeys, xjoinkey);
134-
matched_joinclauses = lappend(matched_joinclauses, joinclause);
129+
matched_keys++;
130+
if (matchedJoinKeysPtr)
131+
{
132+
JoinKey *joinkey = nth(matched_joinkey_index, joinkeys);
133+
matched_joinkeys = lappend(matched_joinkeys, joinkey);
134+
}
135+
136+
if (matchedJoinClausesPtr && joinclauses)
137+
{
138+
Expr *joinclause = nth(matched_joinkey_index,
139+
joinclauses);
140+
matched_joinclauses = lappend(matched_joinclauses, joinclause);
141+
}
135142
}
136143
else
137144
/* A pathkey could not be matched. */
@@ -142,14 +149,20 @@ order_joinkeys_by_pathkeys(List *pathkeys,
142149
* Did we fail to match all the joinkeys?
143150
* Extra pathkeys are no problem.
144151
*/
145-
if (length(joinkeys) != length(matched_joinkeys))
152+
if (matched_keys != length(joinkeys))
146153
{
147-
*matchedJoinClausesPtr = NIL;
148-
return NIL;
154+
if (matchedJoinKeysPtr)
155+
*matchedJoinKeysPtr = NIL;
156+
if (matchedJoinClausesPtr)
157+
*matchedJoinClausesPtr = NIL;
158+
return false;
149159
}
150160

151-
*matchedJoinClausesPtr = matched_joinclauses;
152-
return matched_joinkeys;
161+
if (matchedJoinKeysPtr)
162+
*matchedJoinKeysPtr = matched_joinkeys;
163+
if (matchedJoinClausesPtr)
164+
*matchedJoinClausesPtr = matched_joinclauses;
165+
return true;
153166
}
154167

155168

@@ -221,8 +234,8 @@ get_cheapest_path_for_joinkeys(List *joinkeys,
221234
Path *path = (Path *) lfirst(i);
222235
int better_sort, better_key;
223236

224-
if (joinkeys_pathkeys_match(joinkeys, path->pathkeys, outer_or_inner) &&
225-
length(joinkeys) == length(path->pathkeys) &&
237+
if (order_joinkeys_by_pathkeys(path->pathkeys, joinkeys, NIL,
238+
outer_or_inner, NULL, NULL) &&
226239
pathorder_match(ordering, path->pathorder, &better_sort) &&
227240
better_sort == 0)
228241
{
@@ -246,7 +259,7 @@ get_cheapest_path_for_joinkeys(List *joinkeys,
246259
* 'joinkeys' is a list of join key pairs
247260
* 'tlist' is a relation target list
248261
* 'outer_or_inner' is a flag that selects the desired subkey of a join key
249-
* in 'joinkeys'
262+
* in 'joinkeys'
250263
*
251264
* Returns a list of pathkeys: ((tlvar1)(tlvar2)...(tlvarN)).
252265
* It is a list of lists because of multi-key indexes.
@@ -291,42 +304,6 @@ extract_path_keys(List *joinkeys,
291304
}
292305

293306

294-
/*
295-
* joinkeys_pathkeys_match
296-
*/
297-
static bool
298-
joinkeys_pathkeys_match(List *joinkeys, List *pathkey, int outer_or_inner)
299-
{
300-
JoinKey *xjoinkey;
301-
Var *temp;
302-
Var *tempkey = NULL;
303-
bool found = false;
304-
List *i = NIL;
305-
List *j = NIL;
306-
307-
foreach(i, joinkeys)
308-
{
309-
xjoinkey = (JoinKey *) lfirst(i);
310-
found = false;
311-
foreach(j, pathkey)
312-
{
313-
temp = (Var *) lfirst((List *) lfirst(j));
314-
if (temp == NULL)
315-
continue;
316-
tempkey = extract_join_key(xjoinkey, outer_or_inner);
317-
if (var_equal(tempkey, temp))
318-
{
319-
found = true;
320-
break;
321-
}
322-
}
323-
if (found == false)
324-
return false;
325-
}
326-
return found;
327-
}
328-
329-
330307
/****************************************************************************
331308
* NEW PATHKEY FORMATION
332309
****************************************************************************/

src/include/optimizer/paths.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: paths.h,v 1.24 1999/02/19 05:18:06 momjian Exp $
10+
* $Id: paths.h,v 1.25 1999/02/21 01:55:03 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -54,9 +54,10 @@ extern List *group_clauses_by_hashop(List *restrictinfo_list,
5454
* joinutils.h
5555
* generic join method key/clause routines
5656
*/
57-
extern List *order_joinkeys_by_pathkeys(List *pathkeys,
57+
extern bool order_joinkeys_by_pathkeys(List *pathkeys,
5858
List *joinkeys, List *joinclauses, int outer_or_inner,
59-
List **matchedJoinClausesPtr);
59+
List **matchedJoinKeysPtr,
60+
List **matchedJoinClausesPtr);
6061
extern List *extract_path_keys(List *joinkeys, List *tlist,
6162
int outer_or_inner);
6263
extern Path *get_cheapest_path_for_joinkeys(List *joinkeys,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy