Skip to content
Snippets Groups Projects
Commit 9c38a8d2 authored by Tom Lane's avatar Tom Lane
Browse files

Further tweaking of indexscan cost estimates.

parent 5db0ef84
Branches
Tags
No related merge requests found
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.55 2000/03/30 00:53:29 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.56 2000/04/09 04:31:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -262,9 +262,12 @@ cost_index(Path *path, Query *root, ...@@ -262,9 +262,12 @@ cost_index(Path *path, Query *root,
* effect. Would be nice to do better someday. * effect. Would be nice to do better someday.
*/ */
tuples_fetched = ceil(indexSelectivity * baserel->tuples); tuples_fetched = indexSelectivity * baserel->tuples;
/* Don't believe estimates less than 1... */
if (tuples_fetched < 1.0)
tuples_fetched = 1.0;
if (tuples_fetched > 0 && baserel->pages > 0) if (baserel->pages > 0)
pages_fetched = ceil(baserel->pages * pages_fetched = ceil(baserel->pages *
log(tuples_fetched / baserel->pages + 1.0)); log(tuples_fetched / baserel->pages + 1.0));
else else
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.62 2000/03/30 00:53:30 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.63 2000/04/09 04:31:37 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -902,10 +902,19 @@ genericcostestimate(Query *root, RelOptInfo *rel, ...@@ -902,10 +902,19 @@ genericcostestimate(Query *root, RelOptInfo *rel,
lfirsti(rel->relids)); lfirsti(rel->relids));
/* Estimate the number of index tuples that will be visited */ /* Estimate the number of index tuples that will be visited */
numIndexTuples = ceil(*indexSelectivity * index->tuples); numIndexTuples = *indexSelectivity * index->tuples;
/* Estimate the number of index pages that will be retrieved */ /* Estimate the number of index pages that will be retrieved */
numIndexPages = ceil(*indexSelectivity * index->pages); numIndexPages = *indexSelectivity * index->pages;
/*
* Always estimate at least one tuple and page are touched,
* even when indexSelectivity estimate is tiny.
*/
if (numIndexTuples < 1.0)
numIndexTuples = 1.0;
if (numIndexPages < 1.0)
numIndexPages = 1.0;
/* /*
* Compute the index access cost. * Compute the index access cost.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment