Skip to content

Commit e55985d

Browse files
committed
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...
1 parent 341dc91 commit e55985d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
*
4444
* IDENTIFICATION
45-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.54 2000/03/22 22:08:33 tgl Exp $
45+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.55 2000/03/30 00:53:29 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -262,11 +262,11 @@ cost_index(Path *path, Query *root,
262262
* effect. Would be nice to do better someday.
263263
*/
264264

265-
tuples_fetched = indexSelectivity * baserel->tuples;
265+
tuples_fetched = ceil(indexSelectivity * baserel->tuples);
266266

267267
if (tuples_fetched > 0 && baserel->pages > 0)
268-
pages_fetched = baserel->pages *
269-
log(tuples_fetched / baserel->pages + 1.0);
268+
pages_fetched = ceil(baserel->pages *
269+
log(tuples_fetched / baserel->pages + 1.0));
270270
else
271271
pages_fetched = tuples_fetched;
272272

@@ -594,7 +594,7 @@ cost_hashjoin(Path *path,
594594
* conservatively as the inner disbursion times the inner tuple count.
595595
*/
596596
run_cost += cpu_operator_cost * outer_path->parent->rows *
597-
(inner_path->parent->rows * innerdisbursion);
597+
ceil(inner_path->parent->rows * innerdisbursion);
598598

599599
/*
600600
* Estimate the number of tuples that get through the hashing filter

src/backend/utils/adt/selfuncs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.61 2000/03/23 00:55:42 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.62 2000/03/30 00:53:30 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
2222

2323
#include "postgres.h"
2424

25+
#include <math.h>
26+
2527
#include "access/heapam.h"
2628
#include "catalog/catname.h"
2729
#include "catalog/pg_operator.h"
@@ -900,10 +902,10 @@ genericcostestimate(Query *root, RelOptInfo *rel,
900902
lfirsti(rel->relids));
901903

902904
/* Estimate the number of index tuples that will be visited */
903-
numIndexTuples = *indexSelectivity * index->tuples;
905+
numIndexTuples = ceil(*indexSelectivity * index->tuples);
904906

905907
/* Estimate the number of index pages that will be retrieved */
906-
numIndexPages = *indexSelectivity * index->pages;
908+
numIndexPages = ceil(*indexSelectivity * index->pages);
907909

908910
/*
909911
* Compute the index access cost.

0 commit comments

Comments
 (0)