mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
pathkeys fixes
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.22 1999/02/13 23:16:00 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.23 1999/02/20 19:02:40 momjian Exp $
|
||||||
*
|
*
|
||||||
* HISTORY
|
* HISTORY
|
||||||
* AUTHOR DATE MAJOR EVENT
|
* AUTHOR DATE MAJOR EVENT
|
||||||
@ -213,22 +213,30 @@ print_expr(Node *expr, List *rtable)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* print_pathkeys -
|
* print_pathkeys -
|
||||||
* temporary here. where is keys list of lists
|
* pathkeys list of list of Var's
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
print_pathkeys(List *pathkeys, List *rtable)
|
print_pathkeys(List *pathkeys, List *rtable)
|
||||||
{
|
{
|
||||||
List *k;
|
List *i, *k;
|
||||||
|
|
||||||
printf("(");
|
printf("(");
|
||||||
foreach(k, pathkeys)
|
foreach(i, pathkeys)
|
||||||
{
|
{
|
||||||
Node *var = lfirst((List *) lfirst(k));
|
List pathkey = lfirst(i));
|
||||||
|
|
||||||
|
printf("(");
|
||||||
|
foreach(k, pathkey)
|
||||||
|
{
|
||||||
|
Node *var = lfirst(k);
|
||||||
print_expr(var, rtable);
|
print_expr(var, rtable);
|
||||||
if (lnext(k))
|
if (lnext(k))
|
||||||
printf(", ");
|
printf(", ");
|
||||||
}
|
}
|
||||||
|
printf(") ");
|
||||||
|
if (lnext(i))
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
printf(")\n");
|
printf(")\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.4 1999/02/20 18:01:01 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.5 1999/02/20 19:02:41 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -54,7 +54,19 @@ static List *new_matching_subkeys(Var *subkey, List *considered_subkeys,
|
|||||||
* { {tab1.col1, tab2.col1} }. This allows future joins to use either Var
|
* { {tab1.col1, tab2.col1} }. This allows future joins to use either Var
|
||||||
* as a pre-sorted key to prevent Mergejoins from having to re-sort the Path.
|
* as a pre-sorted key to prevent Mergejoins from having to re-sort the Path.
|
||||||
* They are equal, so they are both primary sort keys. This is why pathkeys
|
* They are equal, so they are both primary sort keys. This is why pathkeys
|
||||||
* is a List of Lists. -- bjm
|
* is a List of Lists.
|
||||||
|
*
|
||||||
|
* For multi-key sorts, if the outer is sorted by a multi-key index, the
|
||||||
|
* multi-key index remains after the join. If the inner has a multi-key
|
||||||
|
* sort, only the primary key of the inner is added to the result.
|
||||||
|
* Mergejoins only join on the primary key. Currently, non-primary keys
|
||||||
|
* in the pathkeys List are of limited value.
|
||||||
|
*
|
||||||
|
* HashJoin has similar functionality. NestJoin does not perform sorting,
|
||||||
|
* and allows non-equajoins, so it does not allow useful pathkeys.
|
||||||
|
*
|
||||||
|
* -- bjm
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -103,6 +115,10 @@ order_joinkeys_by_pathkeys(List *pathkeys,
|
|||||||
List *i = NIL;
|
List *i = NIL;
|
||||||
int matched_joinkey_index = -1;
|
int matched_joinkey_index = -1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reorder the joinkeys by picking out one that matches each pathkey,
|
||||||
|
* and create a new joinkey/joinclause list in pathkey order
|
||||||
|
*/
|
||||||
foreach(i, pathkeys)
|
foreach(i, pathkeys)
|
||||||
{
|
{
|
||||||
pathkey = lfirst(i);
|
pathkey = lfirst(i);
|
||||||
@ -118,11 +134,19 @@ order_joinkeys_by_pathkeys(List *pathkeys,
|
|||||||
matched_joinclauses = lappend(matched_joinclauses, joinclause);
|
matched_joinclauses = lappend(matched_joinclauses, joinclause);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
/* A pathkey could not be matched. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Did we fail to match all the joinkeys?
|
||||||
|
* Extra pathkeys are no problem.
|
||||||
|
*/
|
||||||
|
if (length(joinkeys) != length(matched_joinkeys))
|
||||||
{
|
{
|
||||||
*matchedJoinClausesPtr = NIL;
|
*matchedJoinClausesPtr = NIL;
|
||||||
return NIL;
|
return NIL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
*matchedJoinClausesPtr = matched_joinclauses;
|
*matchedJoinClausesPtr = matched_joinclauses;
|
||||||
return matched_joinkeys;
|
return matched_joinkeys;
|
||||||
@ -133,6 +157,8 @@ order_joinkeys_by_pathkeys(List *pathkeys,
|
|||||||
* match_pathkey_joinkeys
|
* match_pathkey_joinkeys
|
||||||
* Returns the 0-based index into 'joinkeys' of the first joinkey whose
|
* Returns the 0-based index into 'joinkeys' of the first joinkey whose
|
||||||
* outer or inner subkey matches any subkey of 'pathkey'.
|
* outer or inner subkey matches any subkey of 'pathkey'.
|
||||||
|
*
|
||||||
|
* All these keys are equivalent, so any of them can match. See above.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
match_pathkey_joinkeys(List *pathkey,
|
match_pathkey_joinkeys(List *pathkey,
|
||||||
@ -141,8 +167,7 @@ match_pathkey_joinkeys(List *pathkey,
|
|||||||
{
|
{
|
||||||
Var *path_subkey;
|
Var *path_subkey;
|
||||||
int pos;
|
int pos;
|
||||||
List *i = NIL;
|
List *i, *x;
|
||||||
List *x = NIL;
|
|
||||||
JoinKey *jk;
|
JoinKey *jk;
|
||||||
|
|
||||||
foreach(i, pathkey)
|
foreach(i, pathkey)
|
||||||
@ -152,8 +177,7 @@ match_pathkey_joinkeys(List *pathkey,
|
|||||||
foreach(x, joinkeys)
|
foreach(x, joinkeys)
|
||||||
{
|
{
|
||||||
jk = (JoinKey *) lfirst(x);
|
jk = (JoinKey *) lfirst(x);
|
||||||
if (var_equal(path_subkey,
|
if (var_equal(path_subkey, extract_join_key(jk, outer_or_inner)))
|
||||||
extract_join_key(jk, outer_or_inner)))
|
|
||||||
return pos;
|
return pos;
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.38 1999/02/20 18:01:02 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.39 1999/02/20 19:02:42 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: relation.h,v 1.27 1999/02/20 16:28:20 momjian Exp $
|
* $Id: relation.h,v 1.28 1999/02/20 19:02:43 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -142,8 +142,7 @@ typedef struct Path
|
|||||||
|
|
||||||
PathOrder *pathorder;
|
PathOrder *pathorder;
|
||||||
|
|
||||||
List *pathkeys; /*
|
List *pathkeys; /* This is a List of List of Var nodes.
|
||||||
* This is a List of List of Var nodes.
|
|
||||||
* See the top of optimizer/path/pathkeys.c
|
* See the top of optimizer/path/pathkeys.c
|
||||||
* for more information.
|
* for more information.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user