postgresql/src/backend/utils
Tom Lane 31f38f28b0 Redesign the planner's handling of index-descent cost estimation.
Historically we've used a couple of very ad-hoc fudge factors to try to
get the right results when indexes of different sizes would satisfy a
query with the same number of index leaf tuples being visited.  In
commit 21a39de580 I tweaked one of these
fudge factors, with results that proved disastrous for larger indexes.
Commit bf01e34b55 fudged it some more,
but still with not a lot of principle behind it.

What seems like a better way to address these issues is to explicitly model
index-descent costs, since that's what's really at stake when considering
diferent indexes with similar leaf-page-level costs.  We tried that once
long ago, and found that charging random_page_cost per page descended
through was way too much, because upper btree levels tend to stay in cache
in real-world workloads.  However, there's still CPU costs to think about,
and the previous fudge factors can be seen as a crude attempt to account
for those costs.  So this patch replaces those fudge factors with explicit
charges for the number of tuple comparisons needed to descend the index
tree, plus a small charge per page touched in the descent.  The cost
multipliers are chosen so that the resulting charges are in the vicinity of
the historical (pre-9.2) fudge factors for indexes of up to about a million
tuples, while not ballooning unreasonably beyond that, as the old fudge
factor did (even more so in 9.2).

To make this work accurately for btree indexes, add some code that allows
extraction of the known root-page height from a btree.  There's no
equivalent number readily available for other index types, but we can use
the log of the number of index pages as an approximate substitute.

This seems like too much of a behavioral change to risk back-patching,
but it should improve matters going forward.  In 9.2 I'll just revert
the fudge-factor change.
2013-01-11 12:56:58 -05:00
..
adt Redesign the planner's handling of index-descent cost estimation. 2013-01-11 12:56:58 -05:00
cache Invent a "one-shot" variant of CachedPlans for better performance. 2013-01-04 17:42:19 -05:00
error Update copyrights for 2013 2013-01-01 17:15:01 -05:00
fmgr Update copyrights for 2013 2013-01-01 17:15:01 -05:00
hash Update copyrights for 2013 2013-01-01 17:15:01 -05:00
init Fix IsUnderPostmaster/EXEC_BACKEND confusion 2013-01-02 18:39:20 -03:00
mb Update copyrights for 2013 2013-01-01 17:15:01 -05:00
misc Fix background workers for EXEC_BACKEND 2013-01-02 12:01:14 -03:00
mmgr Update copyrights for 2013 2013-01-01 17:15:01 -05:00
resowner Update copyrights for 2013 2013-01-01 17:15:01 -05:00
sort Update copyrights for 2013 2013-01-01 17:15:01 -05:00
time Update copyrights for 2013 2013-01-01 17:15:01 -05:00
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
errcodes.txt Update copyrights for 2013 2013-01-01 17:15:01 -05:00
Gen_dummy_probes.sed Update copyrights for 2013 2013-01-01 17:15:01 -05:00
Gen_fmgrtab.pl Update copyrights for 2013 2013-01-01 17:15:01 -05:00
generate-errcodes.pl Update copyrights for 2013 2013-01-01 17:15:01 -05:00
Makefile Make handling of errcodes.h more consistent with other generated headers. 2011-02-04 09:29:10 -05:00
probes.d Update copyrights for 2013 2013-01-01 17:15:01 -05:00