Commit e55985d3 authored by Tom Lane's avatar Tom Lane

Tweak indexscan cost estimation: round estimated # of tuples visited up

to next integer.  Previously, if selectivity was small, we could compute
very tiny scan cost on the basis of estimating that only 0.001 tuple
would be fetched, which is silly.  This naturally led to some rather
silly plans...
parent 341dc918
...@@ -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.54 2000/03/22 22:08:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.55 2000/03/30 00:53:29 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -262,11 +262,11 @@ cost_index(Path *path, Query *root, ...@@ -262,11 +262,11 @@ cost_index(Path *path, Query *root,
* effect. Would be nice to do better someday. * effect. Would be nice to do better someday.
*/ */
tuples_fetched = indexSelectivity * baserel->tuples; tuples_fetched = ceil(indexSelectivity * baserel->tuples);
if (tuples_fetched > 0 && baserel->pages > 0) if (tuples_fetched > 0 && baserel->pages > 0)
pages_fetched = baserel->pages * pages_fetched = ceil(baserel->pages *
log(tuples_fetched / baserel->pages + 1.0); log(tuples_fetched / baserel->pages + 1.0));
else else
pages_fetched = tuples_fetched; pages_fetched = tuples_fetched;
...@@ -594,7 +594,7 @@ cost_hashjoin(Path *path, ...@@ -594,7 +594,7 @@ cost_hashjoin(Path *path,
* conservatively as the inner disbursion times the inner tuple count. * conservatively as the inner disbursion times the inner tuple count.
*/ */
run_cost += cpu_operator_cost * outer_path->parent->rows * run_cost += cpu_operator_cost * outer_path->parent->rows *
(inner_path->parent->rows * innerdisbursion); ceil(inner_path->parent->rows * innerdisbursion);
/* /*
* Estimate the number of tuples that get through the hashing filter * Estimate the number of tuples that get through the hashing filter
......
...@@ -15,13 +15,15 @@ ...@@ -15,13 +15,15 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.61 2000/03/23 00:55:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.62 2000/03/30 00:53:30 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include <math.h>
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/pg_operator.h" #include "catalog/pg_operator.h"
...@@ -900,10 +902,10 @@ genericcostestimate(Query *root, RelOptInfo *rel, ...@@ -900,10 +902,10 @@ 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 = *indexSelectivity * index->tuples; numIndexTuples = ceil(*indexSelectivity * index->tuples);
/* Estimate the number of index pages that will be retrieved */ /* Estimate the number of index pages that will be retrieved */
numIndexPages = *indexSelectivity * index->pages; numIndexPages = ceil(*indexSelectivity * index->pages);
/* /*
* Compute the index access cost. * Compute the index access cost.
......
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