Make gincostestimate() cope with hypothetical GIN indexes.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 1 Dec 2015 21:24:34 +0000 (16:24 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 1 Dec 2015 21:24:34 +0000 (16:24 -0500)
commit7fb008c5ee59b04005a8ee6c1006249f729e2b03
treee92336057a473997080c8c1a116a623be7a75276
parent95708e1d8e38bc1f7f6ee02c38dd86dd53b9663c
Make gincostestimate() cope with hypothetical GIN indexes.

We tried to fetch statistics data from the index metapage, which does not
work if the index isn't actually present.  If the index is hypothetical,
instead extrapolate some plausible internal statistics based on the index
page count provided by the index-advisor plugin.

There was already some code in gincostestimate() to invent internal stats
in this way, but since it was only meant as a stopgap for pre-9.1 GIN
indexes that hadn't been vacuumed since upgrading, it was pretty crude.
If we want it to support index advisors, we should try a little harder.
A small amount of testing says that it's better to estimate the entry pages
as 90% of the index, not 100%.  Also, estimating the number of entries
(keys) as equal to the heap tuple count could be wildly wrong in either
direction.  Instead, let's estimate 100 entries per entry page.

Perhaps someday somebody will want the index advisor to be able to provide
these numbers more directly, but for the moment this should serve.

Problem report and initial patch by Julien Rouhaud; modified by me to
invent less-bogus internal statistics.  Back-patch to all supported
branches, since we've supported index advisors since 9.0.
src/backend/utils/adt/selfuncs.c