mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +03:00
Fix optimizer and make faster.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_eval.c,v 1.27 1999/02/10 21:02:34 momjian Exp $
|
||||
* $Id: geqo_eval.c,v 1.28 1999/02/12 05:56:47 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -161,8 +161,7 @@ gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *out
|
||||
new_rel = (RelOptInfo *) lfirst(new_rels);
|
||||
rel_count++;
|
||||
|
||||
/* process new_rel->cheapestpath, new_rel->unorderedpath */
|
||||
geqo_rel_paths(new_rel);
|
||||
geqo_set_cheapest(new_rel);
|
||||
|
||||
/* processing of other new_rel attributes */
|
||||
if (new_rel->size <= 0)
|
||||
@@ -282,7 +281,6 @@ init_join_rel(RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinInfo * joininfo)
|
||||
joinrel->width = 0;
|
||||
/* joinrel->targetlist = NIL;*/
|
||||
joinrel->pathlist = NIL;
|
||||
joinrel->unorderedpath = (Path *) NULL;
|
||||
joinrel->cheapestpath = (Path *) NULL;
|
||||
joinrel->pruneable = true;
|
||||
joinrel->classlist = NULL;
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_paths.c,v 1.16 1999/02/11 14:58:50 momjian Exp $
|
||||
* $Id: geqo_paths.c,v 1.17 1999/02/12 05:56:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
|
||||
static List *geqo_prune_rel(RelOptInfo *rel, List *other_rels);
|
||||
static Path *set_paths(RelOptInfo *rel, Path *unorderedpath);
|
||||
|
||||
/*
|
||||
* geqo-prune-rels--
|
||||
@@ -92,62 +91,17 @@ geqo_prune_rel(RelOptInfo *rel, List *other_rels)
|
||||
}
|
||||
|
||||
/*
|
||||
* geqo-rel-paths--
|
||||
* geqo-set-cheapest--
|
||||
* For a relation 'rel' (which corresponds to a join
|
||||
* relation), set pointers to the unordered path and cheapest paths
|
||||
* (if the unordered path isn't the cheapest, it is pruned), and
|
||||
* reset the relation's size field to reflect the join.
|
||||
*
|
||||
* Returns nothing of interest.
|
||||
*
|
||||
* relation), set pointers to the cheapest path
|
||||
*/
|
||||
void
|
||||
geqo_rel_paths(RelOptInfo *rel)
|
||||
geqo_set_cheapest(RelOptInfo *rel)
|
||||
{
|
||||
List *y = NIL;
|
||||
Path *path = (Path *) NULL;
|
||||
JoinPath *cheapest = (JoinPath *) NULL;
|
||||
JoinPath *cheapest = (JoinPath *)set_cheapest(rel, rel->pathlist);
|
||||
|
||||
rel->size = 0;
|
||||
foreach(y, rel->pathlist)
|
||||
{
|
||||
path = (Path *) lfirst(y);
|
||||
|
||||
if (!path->pathorder->ord.sortop)
|
||||
break;
|
||||
}
|
||||
|
||||
cheapest = (JoinPath *) set_paths(rel, path);
|
||||
if (IsA_JoinPath(cheapest))
|
||||
rel->size = compute_joinrel_size(cheapest);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set-path--
|
||||
* Compares the unordered path for a relation with the cheapest path. If
|
||||
* the unordered path is not cheapest, it is pruned.
|
||||
*
|
||||
* Resets the pointers in 'rel' for unordered and cheapest paths.
|
||||
*
|
||||
* Returns the cheapest path.
|
||||
*
|
||||
*/
|
||||
static Path *
|
||||
set_paths(RelOptInfo *rel, Path *unorderedpath)
|
||||
{
|
||||
Path *cheapest = set_cheapest(rel, rel->pathlist);
|
||||
|
||||
/* don't prune if not pruneable -- JMH, 11/23/92 */
|
||||
if (unorderedpath != cheapest
|
||||
&& rel->pruneable)
|
||||
{
|
||||
|
||||
rel->unorderedpath = (Path *) NULL;
|
||||
rel->pathlist = lremove(unorderedpath, rel->pathlist);
|
||||
}
|
||||
else
|
||||
rel->unorderedpath = (Path *) unorderedpath;
|
||||
|
||||
return cheapest;
|
||||
rel->size = 0;
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.27 1999/02/10 21:02:36 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.28 1999/02/12 05:56:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -139,7 +139,7 @@ find_rel_paths(Query *root, List *rels)
|
||||
lastpath = rel->pathlist;
|
||||
while (lnext(lastpath) != NIL)
|
||||
lastpath = lnext(lastpath);
|
||||
prune_rel_path(rel, (Path *) lfirst(lastpath));
|
||||
set_cheapest(rel, rel->pathlist);
|
||||
|
||||
/*
|
||||
* if there is a qualification of sequential scan the selec. value
|
||||
@@ -223,7 +223,7 @@ find_join_paths(Query *root, List *outer_rels, int levels_needed)
|
||||
xfunc_trypullup((RelOptInfo *) lfirst(x));
|
||||
#endif
|
||||
|
||||
prune_rel_paths(new_rels);
|
||||
rels_set_cheapest(new_rels);
|
||||
|
||||
if (BushyPlanFlag)
|
||||
{
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.18 1999/02/10 21:02:39 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.19 1999/02/12 05:56:50 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -216,7 +216,6 @@ init_join_rel(RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinInfo * joininfo)
|
||||
joinrel->width = 0;
|
||||
/* joinrel->targetlist = NIL;*/
|
||||
joinrel->pathlist = NIL;
|
||||
joinrel->unorderedpath = (Path *) NULL;
|
||||
joinrel->cheapestpath = (Path *) NULL;
|
||||
joinrel->pruneable = true;
|
||||
joinrel->classlist = NULL;
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.27 1999/02/11 14:58:54 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.28 1999/02/12 05:56:51 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -77,42 +77,28 @@ prune_joinrel(RelOptInfo *rel, List *other_rels)
|
||||
rel->pathlist,
|
||||
other_rel->pathlist);
|
||||
else
|
||||
result = nconc(result, lcons(other_rel, NIL));
|
||||
result = lappend(result, other_rel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* prune-rel-paths--
|
||||
* rels-set-cheapest
|
||||
* For each relation entry in 'rel-list' (which corresponds to a join
|
||||
* relation), set pointers to the unordered path and cheapest paths
|
||||
* (if the unordered path isn't the cheapest, it is pruned), and
|
||||
* reset the relation's size field to reflect the join.
|
||||
*
|
||||
* Returns nothing of interest.
|
||||
*
|
||||
* relation), set pointers to the cheapest path
|
||||
*/
|
||||
void
|
||||
prune_rel_paths(List *rel_list)
|
||||
rels_set_cheapest(List *rel_list)
|
||||
{
|
||||
List *x = NIL;
|
||||
List *y = NIL;
|
||||
Path *path = NULL;
|
||||
RelOptInfo *rel = (RelOptInfo *) NULL;
|
||||
JoinPath *cheapest = (JoinPath *) NULL;
|
||||
JoinPath *cheapest;
|
||||
|
||||
foreach(x, rel_list)
|
||||
{
|
||||
rel = (RelOptInfo *) lfirst(x);
|
||||
rel->size = 0;
|
||||
foreach(y, rel->pathlist)
|
||||
{
|
||||
path = (Path *) lfirst(y);
|
||||
|
||||
if (!path->pathorder->ord.sortop)
|
||||
break;
|
||||
}
|
||||
cheapest = (JoinPath *) prune_rel_path(rel, path);
|
||||
cheapest = (JoinPath *) set_cheapest(rel, rel->pathlist);
|
||||
if (IsA_JoinPath(cheapest))
|
||||
rel->size = compute_joinrel_size(cheapest);
|
||||
else
|
||||
@@ -121,33 +107,6 @@ prune_rel_paths(List *rel_list)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* prune-rel-path--
|
||||
* Compares the unordered path for a relation with the cheapest path. If
|
||||
* the unordered path is not cheapest, it is pruned.
|
||||
*
|
||||
* Resets the pointers in 'rel' for unordered and cheapest paths.
|
||||
*
|
||||
* Returns the cheapest path.
|
||||
*
|
||||
*/
|
||||
Path *
|
||||
prune_rel_path(RelOptInfo *rel, Path *unorderedpath)
|
||||
{
|
||||
Path *cheapest = set_cheapest(rel, rel->pathlist);
|
||||
|
||||
/* don't prune if not pruneable -- JMH, 11/23/92 */
|
||||
if (unorderedpath != cheapest && rel->pruneable)
|
||||
{
|
||||
rel->unorderedpath = (Path *) NULL;
|
||||
rel->pathlist = lremove(unorderedpath, rel->pathlist);
|
||||
}
|
||||
else
|
||||
rel->unorderedpath = (Path *) unorderedpath;
|
||||
|
||||
return cheapest;
|
||||
}
|
||||
|
||||
/*
|
||||
* merge-joinrels--
|
||||
* Given two lists of rel nodes that are already
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.12 1999/02/10 21:02:40 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.13 1999/02/12 05:56:55 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -78,7 +78,6 @@ find_secondary_index(Query *root, Oid relid)
|
||||
indexnode->width = 0;
|
||||
indexnode->targetlist = NIL;
|
||||
indexnode->pathlist = NIL;
|
||||
indexnode->unorderedpath = NULL;
|
||||
indexnode->cheapestpath = NULL;
|
||||
indexnode->pruneable = true;
|
||||
indexnode->restrictinfo = NIL;
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.32 1999/02/12 02:37:52 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.33 1999/02/12 05:56:57 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -159,12 +159,21 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
List *temp = NIL;
|
||||
int better_key;
|
||||
int better_sort;
|
||||
|
||||
|
||||
#ifdef OPTDUP_DEBUG
|
||||
printf("better_path entry\n");
|
||||
printf("new\n");
|
||||
pprint(new_path);
|
||||
printf("unique_paths\n");
|
||||
pprint(unique_paths);
|
||||
#endif
|
||||
|
||||
foreach(temp, unique_paths)
|
||||
{
|
||||
path = (Path *) lfirst(temp);
|
||||
|
||||
#ifdef OPTDUP_DEBUG
|
||||
#if 0
|
||||
/*def OPTDUP_DEBUG*/
|
||||
if (!pathkeys_match(new_path->pathkeys, path->pathkeys, &better_key) ||
|
||||
better_key != 0)
|
||||
{
|
||||
@@ -210,6 +219,13 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
(better_key != 2 && better_sort == 1)) &&
|
||||
new_path->path_cost <= path->path_cost))
|
||||
{
|
||||
#ifdef OPTDUP_DEBUG
|
||||
printf("replace with new %p old %p better key %d better sort %d\n", &new_path, &path, better_key, better_sort);
|
||||
printf("old\n");
|
||||
pprint(path);
|
||||
printf("new\n");
|
||||
pprint(new_path);
|
||||
#endif
|
||||
*is_new = false;
|
||||
return path;
|
||||
}
|
||||
@@ -223,12 +239,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
(better_key != 1 && better_sort == 2)) &&
|
||||
new_path->path_cost >= path->path_cost))
|
||||
{
|
||||
#ifdef OPTDB_DEBUG
|
||||
printf("better key %d better sort %d\n", better_key, better_sort);
|
||||
printf("new\n");
|
||||
pprint(new_path);
|
||||
#ifdef OPTDUP_DEBUG
|
||||
printf("skip new %p old %p better key %d better sort %d\n", &new_path, &path, better_key, better_sort);
|
||||
printf("old\n");
|
||||
pprint(path);
|
||||
printf("new\n");
|
||||
pprint(new_path);
|
||||
#endif
|
||||
*is_new = false;
|
||||
return NULL;
|
||||
@@ -236,6 +252,12 @@ better_path(Path *new_path, List *unique_paths, bool *is_new)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPTDUP_DEBUG
|
||||
printf("add new %p old %p better key %d better sort %d\n", &new_path, &path, better_key, better_sort);
|
||||
printf("new\n");
|
||||
pprint(new_path);
|
||||
#endif
|
||||
|
||||
*is_new = true;
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.11 1999/02/09 17:03:01 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.12 1999/02/12 05:56:58 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -45,7 +45,6 @@ get_base_rel(Query *root, int relid)
|
||||
rel->width = 0;
|
||||
rel->targetlist = NIL;
|
||||
rel->pathlist = NIL;
|
||||
rel->unorderedpath = (Path *) NULL;
|
||||
rel->cheapestpath = (Path *) NULL;
|
||||
rel->pruneable = true;
|
||||
rel->classlist = NULL;
|
||||
|
Reference in New Issue
Block a user