pgsql: Avoid extrapolating reltuples from tiny VACUUM samples

From: Melanie Plageman <melanieplageman(at)gmail(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid extrapolating reltuples from tiny VACUUM samples
Date: 2026-11-12 21:07:10
Message-ID: E1xRc0k-00000000TpM-38ac@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid extrapolating reltuples from tiny VACUUM samples

Since b46e1e54d, on-access pruning can mark most pages all-visible
before VACUUM or ANALYZE establishes tuple density. VACUUM may then scan
only a tiny tail of mostly empty pages while reltuples is still unknown
or reflects a previously empty table.

When no prior density is available, treat a sample of at most one page
or less than two percent of the relation as insufficient and leave
reltuples unknown instead of extrapolating.

Reported-by: Vaibhav Jain <jainva(at)google(dot)com>
Author: Vaibhav Jain <jainva(at)google(dot)com>
Reviewed-by: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Discussion: https://postgr.es/m/flat/CABa-Az2YXuX%2B_JH8VL89i7oA%2BDC74GvfkSsM9%2B92fGCeWYVCqg%40mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ab79429c26d3980535457cc618c79328a9ebf495

Modified Files
--------------
src/backend/access/heap/vacuumlazy.c | 5 ++---
src/backend/commands/vacuum.c | 21 ++++++++++++++-------
2 files changed, 16 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Melanie Plageman 2026-11-12 21:12:51 pgsql: Scale VACUUM reltuples estimates after relation growth
Previous Message Melanie Plageman 2026-11-12 21:04:15 pgsql: Avoid extrapolating reltuples from tiny VACUUM samples