Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf01e34

Browse files
committed
Tweak genericcostestimate's fudge factor for index size.
To provide some bias against using a large index when a small one would doas well, genericcostestimate adds a "fudge factor", which for a long timewas random_page_cost * index_pages/10000. However, this can grow to be thedominant term in indexscan cost estimates when the index involved is largeenough, a behavior that was never intended. Change to a ln(1 + n/10000)formulation, which has nearly the same behavior up to a few hundred pagesbut tails off significantly thereafter. (A log curve seems correct onfirst principles, since what we're trying to account for here is indexdescent costs, which are typically logarithmic.) Per bug #7619 from NikoKiirala.Possibly this change should get back-patched, but I'm hesitant to mess withcost estimates in stable branches.
1 parenta4e8680 commitbf01e34

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

‎src/backend/utils/adt/selfuncs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6130,12 +6130,14 @@ genericcostestimate(PlannerInfo *root,
61306130
* index would have better selectivity.)
61316131
*
61326132
* We can deal with this by adding a very small "fudge factor" that
6133-
* depends on the index size. The fudge factor used here is one
6134-
* spc_random_page_cost per 10000 index pages, which should be small
6135-
* enough to not alter index-vs-seqscan decisions, but will prevent
6136-
* indexes of different sizes from looking exactly equally attractive.
6133+
* depends on the index size, so that indexes of different sizes won't
6134+
* look exactly equally attractive. To ensure the fudge factor stays
6135+
* small even for very large indexes, use a log function. (We previously
6136+
* used a factor of one spc_random_page_cost per 10000 index pages, which
6137+
* grew too large for large indexes. This expression has about the same
6138+
* growth rate for small indexes, but tails off quickly.)
61376139
*/
6138-
*indexTotalCost+=index->pages*spc_random_page_cost/10000.0;
6140+
*indexTotalCost+=log(1.0+index->pages /10000.0)*spc_random_page_cost;
61396141

61406142
/*
61416143
* CPU cost: any complex expressions in the indexquals will need to be

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp