aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-02-15 20:49:31 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-02-15 20:49:31 +0000
commitb1577a7c78d2d8880b3c0f94689fb75bd074c897 (patch)
treec8d8f0500eb2eaa085d921a46a7d0987ba594a4a /src/backend/utils/adt/selfuncs.c
parent553b5da6a1147881dc1df101ecf9bab75f767ccf (diff)
downloadpostgresql-b1577a7c78d2d8880b3c0f94689fb75bd074c897.tar.gz
postgresql-b1577a7c78d2d8880b3c0f94689fb75bd074c897.zip
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.
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index ab41413432c..30106744ded 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.54 2000/01/26 05:57:14 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.55 2000/02/15 20:49:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -756,7 +756,9 @@ getattstatistics(Oid relid,
static void
genericcostestimate(Query *root, RelOptInfo *rel,
IndexOptInfo *index, List *indexQuals,
- Cost *indexAccessCost, Selectivity *indexSelectivity)
+ Cost *indexStartupCost,
+ Cost *indexTotalCost,
+ Selectivity *indexSelectivity)
{
double numIndexTuples;
double numIndexPages;
@@ -771,8 +773,17 @@ genericcostestimate(Query *root, RelOptInfo *rel,
/* Estimate the number of index pages that will be retrieved */
numIndexPages = *indexSelectivity * index->pages;
- /* Compute the index access cost */
- *indexAccessCost = numIndexPages + cpu_index_page_weight * numIndexTuples;
+ /*
+ * Compute the index access cost.
+ *
+ * Our generic assumption is that the index pages will be read
+ * sequentially, so they have cost 1.0 each, not random_page_cost.
+ * Also, we charge for evaluation of the indexquals at each index tuple.
+ * All the costs are assumed to be paid incrementally during the scan.
+ */
+ *indexStartupCost = 0;
+ *indexTotalCost = numIndexPages +
+ (cpu_index_tuple_cost + cost_qual_eval(indexQuals)) * numIndexTuples;
}
/*
@@ -782,35 +793,43 @@ genericcostestimate(Query *root, RelOptInfo *rel,
void
btcostestimate(Query *root, RelOptInfo *rel,
IndexOptInfo *index, List *indexQuals,
- Cost *indexAccessCost, Selectivity *indexSelectivity)
+ Cost *indexStartupCost,
+ Cost *indexTotalCost,
+ Selectivity *indexSelectivity)
{
genericcostestimate(root, rel, index, indexQuals,
- indexAccessCost, indexSelectivity);
+ indexStartupCost, indexTotalCost, indexSelectivity);
}
void
rtcostestimate(Query *root, RelOptInfo *rel,
IndexOptInfo *index, List *indexQuals,
- Cost *indexAccessCost, Selectivity *indexSelectivity)
+ Cost *indexStartupCost,
+ Cost *indexTotalCost,
+ Selectivity *indexSelectivity)
{
genericcostestimate(root, rel, index, indexQuals,
- indexAccessCost, indexSelectivity);
+ indexStartupCost, indexTotalCost, indexSelectivity);
}
void
hashcostestimate(Query *root, RelOptInfo *rel,
IndexOptInfo *index, List *indexQuals,
- Cost *indexAccessCost, Selectivity *indexSelectivity)
+ Cost *indexStartupCost,
+ Cost *indexTotalCost,
+ Selectivity *indexSelectivity)
{
genericcostestimate(root, rel, index, indexQuals,
- indexAccessCost, indexSelectivity);
+ indexStartupCost, indexTotalCost, indexSelectivity);
}
void
gistcostestimate(Query *root, RelOptInfo *rel,
IndexOptInfo *index, List *indexQuals,
- Cost *indexAccessCost, Selectivity *indexSelectivity)
+ Cost *indexStartupCost,
+ Cost *indexTotalCost,
+ Selectivity *indexSelectivity)
{
genericcostestimate(root, rel, index, indexQuals,
- indexAccessCost, indexSelectivity);
+ indexStartupCost, indexTotalCost, indexSelectivity);
}