Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9c38a8d

Browse files
committed
Further tweaking of indexscan cost estimates.
1 parent 5db0ef8 commit 9c38a8d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 6 additions & 3 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.55 2000/03/30 00:53:29 tgl Exp $
45+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.56 2000/04/09 04:31:36 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -262,9 +262,12 @@ cost_index(Path *path, Query *root,
262262
* effect. Would be nice to do better someday.
263263
*/
264264

265-
tuples_fetched = ceil(indexSelectivity * baserel->tuples);
265+
tuples_fetched = indexSelectivity * baserel->tuples;
266+
/* Don't believe estimates less than 1... */
267+
if (tuples_fetched < 1.0)
268+
tuples_fetched = 1.0;
266269

267-
if (tuples_fetched > 0 && baserel->pages > 0)
270+
if (baserel->pages > 0)
268271
pages_fetched = ceil(baserel->pages *
269272
log(tuples_fetched / baserel->pages + 1.0));
270273
else

src/backend/utils/adt/selfuncs.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.62 2000/03/30 00:53:30 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.63 2000/04/09 04:31:37 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -902,10 +902,19 @@ genericcostestimate(Query *root, RelOptInfo *rel,
902902
lfirsti(rel->relids));
903903

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

907907
/* Estimate the number of index pages that will be retrieved */
908-
numIndexPages = ceil(*indexSelectivity * index->pages);
908+
numIndexPages = *indexSelectivity * index->pages;
909+
910+
/*
911+
* Always estimate at least one tuple and page are touched,
912+
* even when indexSelectivity estimate is tiny.
913+
*/
914+
if (numIndexTuples < 1.0)
915+
numIndexTuples = 1.0;
916+
if (numIndexPages < 1.0)
917+
numIndexPages = 1.0;
909918

910919
/*
911920
* Compute the index access cost.

0 commit comments

Comments
 (0)