Ned T. Crigler wrote:
It appears that the visibility map patch is causing pg_class.reltuples to be
set improperly after a vacuum. For example, it is set to 0 if the map
indicated that no pages in the heap needed to be scanned.
Perhaps reltuples should not be updated unless every page was scanned during
Yeah, vacuum shouldn't overwrite reltuples if it hasn't scanned all pages.
The interplay of vacuum and analyze in VACUUM ANALYZE needs to be
changed too. Currently, the analyze after vacuum doesn't overwrite
reltuples, because the one calculated by vacuum is based on scanning all
pages, and is thus more accurate than the one estimated from the sample
(which is not true anymore, as you pointed out). I think the vacuum
needs to somehow tell analyze whether it updated reltuples or not, so
that analyze can update reltuples if the vacuum didn't scan all pages.