pgsql: Avoid having vacuum set reltuples to 0 on non-empty relations in

From: Andrew Gierth <rhodiumtoad(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Avoid having vacuum set reltuples to 0 on non-empty relations in
Date: 2017-03-16 22:39:31
Message-ID: E1coe3P-0001GR-TM@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.8956.94469@wrigleys.postgresql.org

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/1914c5ea7daaaaba4420f65c991256af5d4a9813

Modified Files
--------------
src/backend/commands/vacuumlazy.c | 15 ++++--
src/test/isolation/expected/vacuum-reltuples.out | 62 ++++++++++++++++++++++++
src/test/isolation/isolation_schedule | 1 +
src/test/isolation/specs/vacuum-reltuples.spec | 45 +++++++++++++++++
4 files changed, 119 insertions(+), 4 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Vik Fearing 2017-03-16 22:44:49 Re: pgsql: Avoid having vacuum set reltuples to 0 on non-empty relations in
Previous Message Robert Haas 2017-03-16 19:10:46 pgsql: Avoid access to uninitialized memory in shared tidbitmap iterati