mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
Optimizer cleanup.
This commit is contained in:
parent
4ea3f728e9
commit
6de25f09b1
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.18 1999/02/11 14:58:53 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.19 1999/02/11 17:00:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -214,12 +214,12 @@ match_paths_joinkeys(List *joinkeys,
|
||||
foreach(i, paths)
|
||||
{
|
||||
Path *path = (Path *) lfirst(i);
|
||||
int more_sort;
|
||||
int better_sort;
|
||||
|
||||
key_match = every_func(joinkeys, path->pathkeys, which_subkey);
|
||||
|
||||
if (pathorder_match(ordering, path->pathorder, &more_sort) &&
|
||||
more_sort == 0 &&
|
||||
if (pathorder_match(ordering, path->pathorder, &better_sort) &&
|
||||
better_sort == 0 &&
|
||||
length(joinkeys) == length(path->pathkeys) && key_match)
|
||||
{
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.15 1999/02/11 04:08:42 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.16 1999/02/11 17:00:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -118,7 +118,7 @@ extract_join_subkey(JoinKey *jk, int which_subkey)
|
||||
*
|
||||
*/
|
||||
bool
|
||||
pathkeys_match(List *keys1, List *keys2, int *longer_key)
|
||||
pathkeys_match(List *keys1, List *keys2, int *better_key)
|
||||
{
|
||||
List *key1,
|
||||
*key2,
|
||||
@ -134,17 +134,17 @@ pathkeys_match(List *keys1, List *keys2, int *longer_key)
|
||||
key1a = lnext(key1a), key2a = lnext(key2a))
|
||||
if (!equal(lfirst(key1a), lfirst(key2a)))
|
||||
{
|
||||
*longer_key = 0;
|
||||
*better_key = 0;
|
||||
return false;
|
||||
}
|
||||
if (key1a != NIL && key2a == NIL)
|
||||
{
|
||||
*longer_key = 1;
|
||||
*better_key = 1;
|
||||
return true;
|
||||
}
|
||||
if (key1a == NIL && key2a != NIL)
|
||||
{
|
||||
*longer_key = 2;
|
||||
*better_key = 2;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -156,15 +156,15 @@ pathkeys_match(List *keys1, List *keys2, int *longer_key)
|
||||
*/
|
||||
if (key1 != NIL && key2 == NIL)
|
||||
{
|
||||
*longer_key = 1;
|
||||
*better_key = 1;
|
||||
return true;
|
||||
}
|
||||
if (key1 == NIL && key2 != NIL)
|
||||
{
|
||||
*longer_key = 2;
|
||||
*better_key = 2;
|
||||
return true;
|
||||
}
|
||||
*longer_key = 0;
|
||||
*better_key = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/ordering.c,v 1.12 1999/02/11 14:58:58 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/ordering.c,v 1.13 1999/02/11 17:00:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -18,7 +18,7 @@
|
||||
#include "optimizer/internal.h"
|
||||
#include "optimizer/ordering.h"
|
||||
|
||||
static bool equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort);
|
||||
static bool equal_sortops_order(Oid *ordering1, Oid *ordering2, int *better_sort);
|
||||
|
||||
/*
|
||||
* equal-path-ordering--
|
||||
@ -28,23 +28,23 @@ static bool equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort);
|
||||
bool
|
||||
pathorder_match(PathOrder *path_ordering1,
|
||||
PathOrder *path_ordering2,
|
||||
int *more_sort)
|
||||
int *better_sort)
|
||||
{
|
||||
|
||||
*more_sort = 0;
|
||||
*better_sort = 0;
|
||||
|
||||
if (path_ordering1 == path_ordering2)
|
||||
return true;
|
||||
|
||||
if (!path_ordering2)
|
||||
{
|
||||
*more_sort = 1;
|
||||
*better_sort = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!path_ordering1)
|
||||
{
|
||||
*more_sort = 2;
|
||||
*better_sort = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -58,14 +58,14 @@ pathorder_match(PathOrder *path_ordering1,
|
||||
{
|
||||
return equal_sortops_order(path_ordering1->ord.sortop,
|
||||
path_ordering2->ord.sortop,
|
||||
more_sort);
|
||||
better_sort);
|
||||
}
|
||||
else if (path_ordering1->ordtype == MERGE_ORDER &&
|
||||
path_ordering2->ordtype == SORTOP_ORDER)
|
||||
{
|
||||
if (!path_ordering2->ord.sortop)
|
||||
{
|
||||
*more_sort = 1;
|
||||
*better_sort = 1;
|
||||
return true;
|
||||
}
|
||||
return path_ordering1->ord.merge->left_operator == path_ordering2->ord.sortop[0];
|
||||
@ -74,7 +74,7 @@ pathorder_match(PathOrder *path_ordering1,
|
||||
{
|
||||
if (!path_ordering1->ord.sortop)
|
||||
{
|
||||
*more_sort = 2;
|
||||
*better_sort = 2;
|
||||
return true;
|
||||
}
|
||||
return path_ordering1->ord.sortop[0] == path_ordering2->ord.merge->left_operator;
|
||||
@ -127,24 +127,24 @@ equal_merge_ordering(MergeOrder *merge_ordering1,
|
||||
* Returns true iff the sort operators are in the same order.
|
||||
*/
|
||||
static bool
|
||||
equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort)
|
||||
equal_sortops_order(Oid *ordering1, Oid *ordering2, int *better_sort)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
*more_sort = 0;
|
||||
*better_sort = 0;
|
||||
|
||||
if (ordering1 == ordering2)
|
||||
return true;
|
||||
|
||||
if (!ordering2)
|
||||
{
|
||||
*more_sort = 1;
|
||||
*better_sort = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ordering1)
|
||||
{
|
||||
*more_sort = 2;
|
||||
*better_sort = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -157,13 +157,13 @@ equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort)
|
||||
|
||||
if (ordering1[i] != 0 && ordering2[i] == 0)
|
||||
{
|
||||
*more_sort = 1;
|
||||
*better_sort = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ordering1[i] == 0 && ordering2[i] != 0)
|
||||
{
|
||||
*more_sort = 2;
|
||||
*better_sort = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.27 1999/02/11 16:09:41 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.28 1999/02/11 17:00:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -157,16 +157,16 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
{
|
||||
Path *path = (Path *) NULL;
|
||||
List *temp = NIL;
|
||||
int longer_key;
|
||||
int more_sort;
|
||||
int better_key;
|
||||
int better_sort;
|
||||
|
||||
foreach(temp, unique_paths)
|
||||
{
|
||||
path = (Path *) lfirst(temp);
|
||||
|
||||
#ifdef OPTDUP_DEBUG
|
||||
if (!pathkeys_match(new_path->pathkeys, path->pathkeys, &longer_key) ||
|
||||
longer_key != 0)
|
||||
if (!pathkeys_match(new_path->pathkeys, path->pathkeys, &better_key) ||
|
||||
better_key != 0)
|
||||
{
|
||||
printf("oldpath\n");
|
||||
pprint(path->pathkeys);
|
||||
@ -177,7 +177,7 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
length(lfirst(path->pathkeys)) < length(lfirst(new_path->pathkeys)))
|
||||
sleep(0); /* set breakpoint here */
|
||||
}
|
||||
if (!pathorder_match(new_path->pathorder, path->pathorder, &more_sort))
|
||||
if (!pathorder_match(new_path->pathorder, path->pathorder, &better_sort))
|
||||
{
|
||||
printf("oldord\n");
|
||||
pprint(path->pathorder);
|
||||
@ -186,9 +186,9 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pathkeys_match(new_path->pathkeys, path->pathkeys, &longer_key))
|
||||
if (pathkeys_match(new_path->pathkeys, path->pathkeys, &better_key))
|
||||
{
|
||||
if (pathorder_match(new_path->pathorder, path->pathorder, &more_sort))
|
||||
if (pathorder_match(new_path->pathorder, path->pathorder, &better_sort))
|
||||
{
|
||||
/*
|
||||
* Replace pathkeys that match exactly, (1,2), (1,2).
|
||||
@ -198,12 +198,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
* over unsorted keys in the same way.
|
||||
*/
|
||||
/* same keys, and new is cheaper, use it */
|
||||
if ((longer_key == 0 && more_sort == 0 &&
|
||||
if ((better_key == 0 && better_sort == 0 &&
|
||||
new_path->path_cost < path->path_cost) ||
|
||||
|
||||
/* new is better, and cheaper, use it */
|
||||
((longer_key == 1 && more_sort != 2) ||
|
||||
(longer_key != 2 && more_sort == 1)) &&
|
||||
((better_key == 1 && better_sort != 2) ||
|
||||
(better_key != 2 && better_sort == 1)) &&
|
||||
new_path->path_cost <= path->path_cost)
|
||||
{
|
||||
*is_new = false;
|
||||
@ -212,12 +212,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
|
||||
/* same keys, new is more expensive, stop */
|
||||
else if
|
||||
((longer_key == 0 && more_sort == 0 &&
|
||||
((better_key == 0 && better_sort == 0 &&
|
||||
new_path->path_cost >= path->path_cost) ||
|
||||
|
||||
/* old is better, and less expensive, stop */
|
||||
((longer_key == 2 && more_sort != 1) ||
|
||||
(longer_key != 1 && more_sort == 2)) &&
|
||||
((better_key == 2 && better_sort != 1) ||
|
||||
(better_key != 1 && better_sort == 2)) &&
|
||||
new_path->path_cost >= path->path_cost)
|
||||
{
|
||||
*is_new = false;
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: keys.h,v 1.10 1999/02/11 04:08:44 momjian Exp $
|
||||
* $Id: keys.h,v 1.11 1999/02/11 17:00:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
extern bool match_indexkey_operand(int indexkey, Var *operand, RelOptInfo *rel);
|
||||
extern Var *extract_join_subkey(JoinKey *jk, int which_subkey);
|
||||
extern bool pathkeys_match(List *keys1, List *keys2, int *longer_key);
|
||||
extern bool pathkeys_match(List *keys1, List *keys2, int *better_key);
|
||||
extern List *collect_index_pathkeys(int *index_keys, List *tlist);
|
||||
|
||||
#endif /* KEYS_H */
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: ordering.h,v 1.11 1999/02/11 14:59:09 momjian Exp $
|
||||
* $Id: ordering.h,v 1.12 1999/02/11 17:00:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -16,7 +16,7 @@
|
||||
#include <nodes/relation.h>
|
||||
|
||||
extern bool pathorder_match(PathOrder *path_ordering1,
|
||||
PathOrder *path_ordering2, int *more_sort);
|
||||
PathOrder *path_ordering2, int *better_sort);
|
||||
extern bool equal_path_merge_ordering(Oid *path_ordering,
|
||||
MergeOrder *merge_ordering);
|
||||
extern bool equal_merge_ordering(MergeOrder *merge_ordering1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user