mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
New cost model for planning, incorporating a penalty for random page
accesses versus sequential accesses, a (very crude) estimate of the effects of caching on random page accesses, and cost to evaluate WHERE- clause expressions. Export critical parameters for this model as SET variables. Also, create SET variables for the planner's enable flags (enable_seqscan, enable_indexscan, etc) so that these can be controlled more conveniently than via PGOPTIONS. Planner now estimates both startup cost (cost before retrieving first tuple) and total cost of each path, so it can optimize queries with LIMIT on a reasonable basis by interpolating between these costs. Same facility is a win for EXISTS(...) subqueries and some other cases. Redesign pathkey representation to achieve a major speedup in planning (I saw as much as 5X on a 10-way join); also minor changes in planner to reduce memory consumption by recycling discarded Path nodes and not constructing unnecessary lists. Minor cleanups to display more-plausible costs in some cases in EXPLAIN output. Initdb forced by change in interface to index cost estimation functions.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_eval.c,v 1.47 2000/02/07 04:40:58 tgl Exp $
|
||||
* $Id: geqo_eval.c,v 1.48 2000/02/15 20:49:14 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -96,8 +96,13 @@ geqo_eval(Query *root, Gene *tour, int num_gene)
|
||||
/* construct the best path for the given combination of relations */
|
||||
joinrel = gimme_tree(root, tour, 0, num_gene, NULL);
|
||||
|
||||
/* compute fitness */
|
||||
fitness = joinrel->cheapestpath->path_cost;
|
||||
/*
|
||||
* compute fitness
|
||||
*
|
||||
* XXX geqo does not currently support optimization for partial
|
||||
* result retrieval --- how to fix?
|
||||
*/
|
||||
fitness = joinrel->cheapest_total_path->total_cost;
|
||||
|
||||
/* restore join_rel_list */
|
||||
root->join_rel_list = savelist;
|
||||
@@ -155,8 +160,8 @@ gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *old
|
||||
rel_count++;
|
||||
Assert(length(new_rel->relids) == rel_count);
|
||||
|
||||
/* Find and save the cheapest path for this rel */
|
||||
set_cheapest(new_rel, new_rel->pathlist);
|
||||
/* Find and save the cheapest paths for this rel */
|
||||
set_cheapest(new_rel);
|
||||
|
||||
return gimme_tree(root, tour, rel_count, num_gene, new_rel);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_misc.c,v 1.27 2000/02/07 04:40:58 tgl Exp $
|
||||
* $Id: geqo_misc.c,v 1.28 2000/02/15 20:49:14 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -179,8 +179,9 @@ geqo_print_path(Query *root, Path *path, int indent)
|
||||
if (join)
|
||||
{
|
||||
jp = (JoinPath *) path;
|
||||
printf("%s rows=%.0f cost=%f\n",
|
||||
ptype, path->parent->rows, path->path_cost);
|
||||
printf("%s rows=%.0f cost=%.2f..%.2f\n",
|
||||
ptype, path->parent->rows,
|
||||
path->startup_cost, path->total_cost);
|
||||
switch (nodeTag(path))
|
||||
{
|
||||
case T_MergePath:
|
||||
@@ -215,8 +216,9 @@ geqo_print_path(Query *root, Path *path, int indent)
|
||||
{
|
||||
int relid = lfirsti(path->parent->relids);
|
||||
|
||||
printf("%s(%d) rows=%.0f cost=%f\n",
|
||||
ptype, relid, path->parent->rows, path->path_cost);
|
||||
printf("%s(%d) rows=%.0f cost=%.2f..%.2f\n",
|
||||
ptype, relid, path->parent->rows,
|
||||
path->startup_cost, path->total_cost);
|
||||
|
||||
if (IsA(path, IndexPath))
|
||||
{
|
||||
@@ -241,6 +243,9 @@ geqo_print_rel(Query *root, RelOptInfo *rel)
|
||||
foreach(l, rel->pathlist)
|
||||
geqo_print_path(root, lfirst(l), 1);
|
||||
|
||||
printf("\tcheapest path:\n");
|
||||
geqo_print_path(root, rel->cheapestpath, 1);
|
||||
printf("\tcheapest startup path:\n");
|
||||
geqo_print_path(root, rel->cheapest_startup_path, 1);
|
||||
|
||||
printf("\tcheapest total path:\n");
|
||||
geqo_print_path(root, rel->cheapest_total_path, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user