提交 23c30246 编写于 作者: B Bruce Momjian

pathkeys.c cleanup.

上级 9d197856
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.23 1999/02/20 19:02:40 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.24 1999/02/21 01:55:01 momjian Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -223,7 +223,7 @@ print_pathkeys(List *pathkeys, List *rtable) ...@@ -223,7 +223,7 @@ print_pathkeys(List *pathkeys, List *rtable)
printf("("); printf("(");
foreach(i, pathkeys) foreach(i, pathkeys)
{ {
List pathkey = lfirst(i)); List pathkey = lfirst(i);
printf("("); printf("(");
foreach(k, pathkey) foreach(k, pathkey)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.30 1999/02/19 05:18:04 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.31 1999/02/21 01:55:02 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -309,11 +309,12 @@ match_unsorted_outer(RelOptInfo *joinrel, ...@@ -309,11 +309,12 @@ match_unsorted_outer(RelOptInfo *joinrel,
{ {
List *jmkeys = xmergeinfo->jmethod.jmkeys; List *jmkeys = xmergeinfo->jmethod.jmkeys;
matchedJoinKeys = order_joinkeys_by_pathkeys(outerpath->pathkeys, order_joinkeys_by_pathkeys(outerpath->pathkeys,
jmkeys, jmkeys,
clauses, clauses,
OUTER, OUTER,
&matchedJoinClauses); &matchedJoinKeys,
&matchedJoinClauses);
merge_pathkeys = new_join_pathkeys(outerpath->pathkeys, merge_pathkeys = new_join_pathkeys(outerpath->pathkeys,
joinrel->targetlist, clauses); joinrel->targetlist, clauses);
} }
...@@ -449,10 +450,11 @@ match_unsorted_inner(RelOptInfo *joinrel, ...@@ -449,10 +450,11 @@ match_unsorted_inner(RelOptInfo *joinrel,
{ {
List *jmkeys = xmergeinfo->jmethod.jmkeys; List *jmkeys = xmergeinfo->jmethod.jmkeys;
matchedJoinKeys = order_joinkeys_by_pathkeys(innerpath->pathkeys, order_joinkeys_by_pathkeys(innerpath->pathkeys,
jmkeys, jmkeys,
clauses, clauses,
INNER, INNER,
&matchedJoinKeys,
&matchedJoinClauses); &matchedJoinClauses);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.5 1999/02/20 19:02:41 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.6 1999/02/21 01:55:02 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
static int match_pathkey_joinkeys(List *pathkey, List *joinkeys, static int match_pathkey_joinkeys(List *pathkey, List *joinkeys,
int outer_or_inner); int outer_or_inner);
static bool joinkeys_pathkeys_match(List *joinkeys, List *pathkey,
int outer_or_inner);
static List *new_join_pathkey(List *subkeys, List *considered_subkeys, static List *new_join_pathkey(List *subkeys, List *considered_subkeys,
List *join_rel_tlist, List *joinclauses); List *join_rel_tlist, List *joinclauses);
static List *new_matching_subkeys(Var *subkey, List *considered_subkeys, static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
...@@ -94,19 +92,20 @@ static List *new_matching_subkeys(Var *subkey, List *considered_subkeys, ...@@ -94,19 +92,20 @@ static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
* Returns the join keys and corresponding join clauses in a list if all * Returns the join keys and corresponding join clauses in a list if all
* of the path keys were matched: * of the path keys were matched:
* ( * (
* ( (outerkey0 innerkey0) ... (outerkeyN innerkeyN) ) * ( (outerkey0 innerkey0) ... (outerkeyN or innerkeyN) )
* ( clause0 ... clauseN ) * ( clause0 ... clauseN )
* ) * )
* and nil otherwise. * and nil otherwise.
* *
* Returns a list of matched join keys and a list of matched join clauses * Returns a list of matched join keys and a list of matched join clauses
* in matchedJoinClausesPtr. - ay 11/94 * in pointers if valid order can be found.
*/ */
List * bool
order_joinkeys_by_pathkeys(List *pathkeys, order_joinkeys_by_pathkeys(List *pathkeys,
List *joinkeys, List *joinkeys,
List *joinclauses, List *joinclauses,
int outer_or_inner, int outer_or_inner,
List **matchedJoinKeysPtr,
List **matchedJoinClausesPtr) List **matchedJoinClausesPtr)
{ {
List *matched_joinkeys = NIL; List *matched_joinkeys = NIL;
...@@ -114,7 +113,7 @@ order_joinkeys_by_pathkeys(List *pathkeys, ...@@ -114,7 +113,7 @@ order_joinkeys_by_pathkeys(List *pathkeys,
List *pathkey = NIL; List *pathkey = NIL;
List *i = NIL; List *i = NIL;
int matched_joinkey_index = -1; int matched_joinkey_index = -1;
int matched_keys = 0;
/* /*
* Reorder the joinkeys by picking out one that matches each pathkey, * Reorder the joinkeys by picking out one that matches each pathkey,
* and create a new joinkey/joinclause list in pathkey order * and create a new joinkey/joinclause list in pathkey order
...@@ -127,11 +126,19 @@ order_joinkeys_by_pathkeys(List *pathkeys, ...@@ -127,11 +126,19 @@ order_joinkeys_by_pathkeys(List *pathkeys,
if (matched_joinkey_index != -1) if (matched_joinkey_index != -1)
{ {
List *xjoinkey = nth(matched_joinkey_index, joinkeys); matched_keys++;
List *joinclause = nth(matched_joinkey_index, joinclauses); if (matchedJoinKeysPtr)
{
matched_joinkeys = lappend(matched_joinkeys, xjoinkey); JoinKey *joinkey = nth(matched_joinkey_index, joinkeys);
matched_joinclauses = lappend(matched_joinclauses, joinclause); matched_joinkeys = lappend(matched_joinkeys, joinkey);
}
if (matchedJoinClausesPtr && joinclauses)
{
Expr *joinclause = nth(matched_joinkey_index,
joinclauses);
matched_joinclauses = lappend(matched_joinclauses, joinclause);
}
} }
else else
/* A pathkey could not be matched. */ /* A pathkey could not be matched. */
...@@ -142,14 +149,20 @@ order_joinkeys_by_pathkeys(List *pathkeys, ...@@ -142,14 +149,20 @@ order_joinkeys_by_pathkeys(List *pathkeys,
* Did we fail to match all the joinkeys? * Did we fail to match all the joinkeys?
* Extra pathkeys are no problem. * Extra pathkeys are no problem.
*/ */
if (length(joinkeys) != length(matched_joinkeys)) if (matched_keys != length(joinkeys))
{ {
*matchedJoinClausesPtr = NIL; if (matchedJoinKeysPtr)
return NIL; *matchedJoinKeysPtr = NIL;
if (matchedJoinClausesPtr)
*matchedJoinClausesPtr = NIL;
return false;
} }
*matchedJoinClausesPtr = matched_joinclauses; if (matchedJoinKeysPtr)
return matched_joinkeys; *matchedJoinKeysPtr = matched_joinkeys;
if (matchedJoinClausesPtr)
*matchedJoinClausesPtr = matched_joinclauses;
return true;
} }
...@@ -221,8 +234,8 @@ get_cheapest_path_for_joinkeys(List *joinkeys, ...@@ -221,8 +234,8 @@ get_cheapest_path_for_joinkeys(List *joinkeys,
Path *path = (Path *) lfirst(i); Path *path = (Path *) lfirst(i);
int better_sort, better_key; int better_sort, better_key;
if (joinkeys_pathkeys_match(joinkeys, path->pathkeys, outer_or_inner) && if (order_joinkeys_by_pathkeys(path->pathkeys, joinkeys, NIL,
length(joinkeys) == length(path->pathkeys) && outer_or_inner, NULL, NULL) &&
pathorder_match(ordering, path->pathorder, &better_sort) && pathorder_match(ordering, path->pathorder, &better_sort) &&
better_sort == 0) better_sort == 0)
{ {
...@@ -246,7 +259,7 @@ get_cheapest_path_for_joinkeys(List *joinkeys, ...@@ -246,7 +259,7 @@ get_cheapest_path_for_joinkeys(List *joinkeys,
* 'joinkeys' is a list of join key pairs * 'joinkeys' is a list of join key pairs
* 'tlist' is a relation target list * 'tlist' is a relation target list
* 'outer_or_inner' is a flag that selects the desired subkey of a join key * 'outer_or_inner' is a flag that selects the desired subkey of a join key
* in 'joinkeys' * in 'joinkeys'
* *
* Returns a list of pathkeys: ((tlvar1)(tlvar2)...(tlvarN)). * Returns a list of pathkeys: ((tlvar1)(tlvar2)...(tlvarN)).
* It is a list of lists because of multi-key indexes. * It is a list of lists because of multi-key indexes.
...@@ -291,42 +304,6 @@ extract_path_keys(List *joinkeys, ...@@ -291,42 +304,6 @@ extract_path_keys(List *joinkeys,
} }
/*
* joinkeys_pathkeys_match
*/
static bool
joinkeys_pathkeys_match(List *joinkeys, List *pathkey, int outer_or_inner)
{
JoinKey *xjoinkey;
Var *temp;
Var *tempkey = NULL;
bool found = false;
List *i = NIL;
List *j = NIL;
foreach(i, joinkeys)
{
xjoinkey = (JoinKey *) lfirst(i);
found = false;
foreach(j, pathkey)
{
temp = (Var *) lfirst((List *) lfirst(j));
if (temp == NULL)
continue;
tempkey = extract_join_key(xjoinkey, outer_or_inner);
if (var_equal(tempkey, temp))
{
found = true;
break;
}
}
if (found == false)
return false;
}
return found;
}
/**************************************************************************** /****************************************************************************
* NEW PATHKEY FORMATION * NEW PATHKEY FORMATION
****************************************************************************/ ****************************************************************************/
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: paths.h,v 1.24 1999/02/19 05:18:06 momjian Exp $ * $Id: paths.h,v 1.25 1999/02/21 01:55:03 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -54,9 +54,10 @@ extern List *group_clauses_by_hashop(List *restrictinfo_list, ...@@ -54,9 +54,10 @@ extern List *group_clauses_by_hashop(List *restrictinfo_list,
* joinutils.h * joinutils.h
* generic join method key/clause routines * generic join method key/clause routines
*/ */
extern List *order_joinkeys_by_pathkeys(List *pathkeys, extern bool order_joinkeys_by_pathkeys(List *pathkeys,
List *joinkeys, List *joinclauses, int outer_or_inner, List *joinkeys, List *joinclauses, int outer_or_inner,
List **matchedJoinClausesPtr); List **matchedJoinKeysPtr,
List **matchedJoinClausesPtr);
extern List *extract_path_keys(List *joinkeys, List *tlist, extern List *extract_path_keys(List *joinkeys, List *tlist,
int outer_or_inner); int outer_or_inner);
extern Path *get_cheapest_path_for_joinkeys(List *joinkeys, extern Path *get_cheapest_path_for_joinkeys(List *joinkeys,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册