Avoid having vacuum set reltuples to 0 on non-empty relations in the
authorAndrew Gierth
Thu, 16 Mar 2017 22:32:56 +0000 (22:32 +0000)
committerAndrew Gierth
Thu, 16 Mar 2017 22:32:56 +0000 (22:32 +0000)
commit269efd052922489cf91fd0bc5a80c2008f553b49
tree608c35310838b016102bc4911c3d0180e05b30b9
parente0c8bd704c63baccc03e22112d411f7edb5f80c7
Avoid having vacuum set reltuples to 0 on non-empty relations in the
presence of page pins, which leads to serious estimation errors in the
planner.  This particularly affects small heavily-accessed tables,
especially where locking (e.g. from FK constraints) forces frequent
vacuums for mxid cleanup.

Fix by keeping separate track of pages whose live tuples were actually
counted vs. pages that were only scanned for freezing purposes.  Thus,
reltuples can only be set to 0 if all pages of the relation were
actually counted.

Backpatch to all supported versions.

Per bug #14057 from Nicolas Baccelli, analyzed by me.

Discussion: https://postgr.es/m/20160331103739[email protected]
src/backend/commands/vacuumlazy.c