Commit 6de25f09 authored by Bruce Momjian's avatar Bruce Momjian

Optimizer cleanup.

parent 4ea3f728
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -214,12 +214,12 @@ match_paths_joinkeys(List *joinkeys,
foreach(i, paths) foreach(i, paths)
{ {
Path *path = (Path *) lfirst(i); Path *path = (Path *) lfirst(i);
int more_sort; int better_sort;
key_match = every_func(joinkeys, path->pathkeys, which_subkey); key_match = every_func(joinkeys, path->pathkeys, which_subkey);
if (pathorder_match(ordering, path->pathorder, &more_sort) && if (pathorder_match(ordering, path->pathorder, &better_sort) &&
more_sort == 0 && better_sort == 0 &&
length(joinkeys) == length(path->pathkeys) && key_match) length(joinkeys) == length(path->pathkeys) && key_match)
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -118,7 +118,7 @@ extract_join_subkey(JoinKey *jk, int which_subkey)
* *
*/ */
bool bool
pathkeys_match(List *keys1, List *keys2, int *longer_key) pathkeys_match(List *keys1, List *keys2, int *better_key)
{ {
List *key1, List *key1,
*key2, *key2,
...@@ -134,17 +134,17 @@ pathkeys_match(List *keys1, List *keys2, int *longer_key) ...@@ -134,17 +134,17 @@ pathkeys_match(List *keys1, List *keys2, int *longer_key)
key1a = lnext(key1a), key2a = lnext(key2a)) key1a = lnext(key1a), key2a = lnext(key2a))
if (!equal(lfirst(key1a), lfirst(key2a))) if (!equal(lfirst(key1a), lfirst(key2a)))
{ {
*longer_key = 0; *better_key = 0;
return false; return false;
} }
if (key1a != NIL && key2a == NIL) if (key1a != NIL && key2a == NIL)
{ {
*longer_key = 1; *better_key = 1;
return true; return true;
} }
if (key1a == NIL && key2a != NIL) if (key1a == NIL && key2a != NIL)
{ {
*longer_key = 2; *better_key = 2;
return true; return true;
} }
} }
...@@ -156,15 +156,15 @@ pathkeys_match(List *keys1, List *keys2, int *longer_key) ...@@ -156,15 +156,15 @@ pathkeys_match(List *keys1, List *keys2, int *longer_key)
*/ */
if (key1 != NIL && key2 == NIL) if (key1 != NIL && key2 == NIL)
{ {
*longer_key = 1; *better_key = 1;
return true; return true;
} }
if (key1 == NIL && key2 != NIL) if (key1 == NIL && key2 != NIL)
{ {
*longer_key = 2; *better_key = 2;
return true; return true;
} }
*longer_key = 0; *better_key = 0;
return true; return true;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 @@ ...@@ -18,7 +18,7 @@
#include "optimizer/internal.h" #include "optimizer/internal.h"
#include "optimizer/ordering.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-- * equal-path-ordering--
...@@ -28,23 +28,23 @@ static bool equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort); ...@@ -28,23 +28,23 @@ static bool equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort);
bool bool
pathorder_match(PathOrder *path_ordering1, pathorder_match(PathOrder *path_ordering1,
PathOrder *path_ordering2, PathOrder *path_ordering2,
int *more_sort) int *better_sort)
{ {
*more_sort = 0; *better_sort = 0;
if (path_ordering1 == path_ordering2) if (path_ordering1 == path_ordering2)
return true; return true;
if (!path_ordering2) if (!path_ordering2)
{ {
*more_sort = 1; *better_sort = 1;
return true; return true;
} }
if (!path_ordering1) if (!path_ordering1)
{ {
*more_sort = 2; *better_sort = 2;
return true; return true;
} }
...@@ -58,14 +58,14 @@ pathorder_match(PathOrder *path_ordering1, ...@@ -58,14 +58,14 @@ pathorder_match(PathOrder *path_ordering1,
{ {
return equal_sortops_order(path_ordering1->ord.sortop, return equal_sortops_order(path_ordering1->ord.sortop,
path_ordering2->ord.sortop, path_ordering2->ord.sortop,
more_sort); better_sort);
} }
else if (path_ordering1->ordtype == MERGE_ORDER && else if (path_ordering1->ordtype == MERGE_ORDER &&
path_ordering2->ordtype == SORTOP_ORDER) path_ordering2->ordtype == SORTOP_ORDER)
{ {
if (!path_ordering2->ord.sortop) if (!path_ordering2->ord.sortop)
{ {
*more_sort = 1; *better_sort = 1;
return true; return true;
} }
return path_ordering1->ord.merge->left_operator == path_ordering2->ord.sortop[0]; return path_ordering1->ord.merge->left_operator == path_ordering2->ord.sortop[0];
...@@ -74,7 +74,7 @@ pathorder_match(PathOrder *path_ordering1, ...@@ -74,7 +74,7 @@ pathorder_match(PathOrder *path_ordering1,
{ {
if (!path_ordering1->ord.sortop) if (!path_ordering1->ord.sortop)
{ {
*more_sort = 2; *better_sort = 2;
return true; return true;
} }
return path_ordering1->ord.sortop[0] == path_ordering2->ord.merge->left_operator; return path_ordering1->ord.sortop[0] == path_ordering2->ord.merge->left_operator;
...@@ -127,24 +127,24 @@ equal_merge_ordering(MergeOrder *merge_ordering1, ...@@ -127,24 +127,24 @@ equal_merge_ordering(MergeOrder *merge_ordering1,
* Returns true iff the sort operators are in the same order. * Returns true iff the sort operators are in the same order.
*/ */
static bool 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; int i = 0;
*more_sort = 0; *better_sort = 0;
if (ordering1 == ordering2) if (ordering1 == ordering2)
return true; return true;
if (!ordering2) if (!ordering2)
{ {
*more_sort = 1; *better_sort = 1;
return true; return true;
} }
if (!ordering1) if (!ordering1)
{ {
*more_sort = 2; *better_sort = 2;
return true; return true;
} }
...@@ -157,13 +157,13 @@ equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort) ...@@ -157,13 +157,13 @@ equal_sortops_order(Oid *ordering1, Oid *ordering2, int *more_sort)
if (ordering1[i] != 0 && ordering2[i] == 0) if (ordering1[i] != 0 && ordering2[i] == 0)
{ {
*more_sort = 1; *better_sort = 1;
return true; return true;
} }
if (ordering1[i] == 0 && ordering2[i] != 0) if (ordering1[i] == 0 && ordering2[i] != 0)
{ {
*more_sort = 2; *better_sort = 2;
return true; return true;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -157,16 +157,16 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
{ {
Path *path = (Path *) NULL; Path *path = (Path *) NULL;
List *temp = NIL; List *temp = NIL;
int longer_key; int better_key;
int more_sort; int better_sort;
foreach(temp, unique_paths) foreach(temp, unique_paths)
{ {
path = (Path *) lfirst(temp); path = (Path *) lfirst(temp);
#ifdef OPTDUP_DEBUG #ifdef OPTDUP_DEBUG
if (!pathkeys_match(new_path->pathkeys, path->pathkeys, &longer_key) || if (!pathkeys_match(new_path->pathkeys, path->pathkeys, &better_key) ||
longer_key != 0) better_key != 0)
{ {
printf("oldpath\n"); printf("oldpath\n");
pprint(path->pathkeys); pprint(path->pathkeys);
...@@ -177,7 +177,7 @@ better_path(Path *new_path, List *unique_paths, bool *is_new) ...@@ -177,7 +177,7 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
length(lfirst(path->pathkeys)) < length(lfirst(new_path->pathkeys))) length(lfirst(path->pathkeys)) < length(lfirst(new_path->pathkeys)))
sleep(0); /* set breakpoint here */ 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"); printf("oldord\n");
pprint(path->pathorder); pprint(path->pathorder);
...@@ -186,9 +186,9 @@ better_path(Path *new_path, List *unique_paths, bool *is_new) ...@@ -186,9 +186,9 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
} }
#endif #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). * Replace pathkeys that match exactly, (1,2), (1,2).
...@@ -198,12 +198,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new) ...@@ -198,12 +198,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
* over unsorted keys in the same way. * over unsorted keys in the same way.
*/ */
/* same keys, and new is cheaper, use it */ /* 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_path->path_cost < path->path_cost) ||
/* new is better, and cheaper, use it */ /* new is better, and cheaper, use it */
((longer_key == 1 && more_sort != 2) || ((better_key == 1 && better_sort != 2) ||
(longer_key != 2 && more_sort == 1)) && (better_key != 2 && better_sort == 1)) &&
new_path->path_cost <= path->path_cost) new_path->path_cost <= path->path_cost)
{ {
*is_new = false; *is_new = false;
...@@ -212,12 +212,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new) ...@@ -212,12 +212,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
/* same keys, new is more expensive, stop */ /* same keys, new is more expensive, stop */
else if else if
((longer_key == 0 && more_sort == 0 && ((better_key == 0 && better_sort == 0 &&
new_path->path_cost >= path->path_cost) || new_path->path_cost >= path->path_cost) ||
/* old is better, and less expensive, stop */ /* old is better, and less expensive, stop */
((longer_key == 2 && more_sort != 1) || ((better_key == 2 && better_sort != 1) ||
(longer_key != 1 && more_sort == 2)) && (better_key != 1 && better_sort == 2)) &&
new_path->path_cost >= path->path_cost) new_path->path_cost >= path->path_cost)
{ {
*is_new = false; *is_new = false;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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 @@ ...@@ -18,7 +18,7 @@
extern bool match_indexkey_operand(int indexkey, Var *operand, RelOptInfo *rel); extern bool match_indexkey_operand(int indexkey, Var *operand, RelOptInfo *rel);
extern Var *extract_join_subkey(JoinKey *jk, int which_subkey); 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); extern List *collect_index_pathkeys(int *index_keys, List *tlist);
#endif /* KEYS_H */ #endif /* KEYS_H */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * 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 @@ ...@@ -16,7 +16,7 @@
#include <nodes/relation.h> #include <nodes/relation.h>
extern bool pathorder_match(PathOrder *path_ordering1, 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, extern bool equal_path_merge_ordering(Oid *path_ordering,
MergeOrder *merge_ordering); MergeOrder *merge_ordering);
extern bool equal_merge_ordering(MergeOrder *merge_ordering1, extern bool equal_merge_ordering(MergeOrder *merge_ordering1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment