Skip to content

Commit 3485cc3

Browse files
committed
Adjust cost_nonsequential_access() to have more reasonable behavior
when random_page_cost has a small value. Per Manfred Koizar, though I didn't use his equation exactly.
1 parent 387b38b commit 3485cc3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Portions Copyright (c) 1994, Regents of the University of California
5050
*
5151
* IDENTIFICATION
52-
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.130 2004/06/05 01:55:04 tgl Exp $
52+
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.131 2004/06/10 21:02:00 tgl Exp $
5353
*
5454
*-------------------------------------------------------------------------
5555
*/
@@ -189,11 +189,12 @@ cost_seqscan(Path *path, Query *root,
189189
* for now by assuming we are given an effective_cache_size parameter.
190190
*
191191
* Given a guesstimated cache size, we estimate the actual I/O cost per page
192-
* with the entirely ad-hoc equations:
193-
* if relpages >= effective_cache_size:
194-
* random_page_cost * (1 - (effective_cache_size/relpages)/2)
195-
* if relpages < effective_cache_size:
196-
* 1 + (random_page_cost/2-1) * (relpages/effective_cache_size) ** 2
192+
* with the entirely ad-hoc equations (writing relsize for
193+
* relpages/effective_cache_size):
194+
* if relsize >= 1:
195+
* random_page_cost - (random_page_cost-1)/2 * (1/relsize)
196+
* if relsize < 1:
197+
* 1 + ((random_page_cost-1)/2) * relsize ** 2
197198
* These give the right asymptotic behavior (=> 1.0 as relpages becomes
198199
* small, => random_page_cost as it becomes large) and meet in the middle
199200
* with the estimate that the cache is about 50% effective for a relation
@@ -213,9 +214,9 @@ cost_nonsequential_access(double relpages)
213214
relsize = relpages / effective_cache_size;
214215

215216
if (relsize >= 1.0)
216-
return random_page_cost * (1.0 - 0.5 / relsize);
217+
return random_page_cost - (random_page_cost - 1.0) * 0.5 / relsize;
217218
else
218-
return 1.0 + (random_page_cost * 0.5 - 1.0) * relsize * relsize;
219+
return 1.0 + (random_page_cost - 1.0) * 0.5 * relsize * relsize;
219220
}
220221

221222
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy