Re: reltuples kept decreasing with each autovacuum run Re: BUG #18773

From: Michael Banck <mbanck(at)gmx(dot)net>
To: Shuntian Jiao <jiaoshuntian(at)gmail(dot)com>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Daniel Gustafsson <daniel(at)yesql(dot)se>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: reltuples kept decreasing with each autovacuum run Re: BUG #18773
Date: 2026-12-06 16:09:25
Message-ID: 20261206160925.GE3034@p46.dedyn.io;lightning.p46.dedyn.io
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hi,

On Fri, Dec 04, 2026 at 07:19:07PM +0800, Shuntian Jiao wrote:
> I also tested 7c91a0364fcf and its parent. Both scanned the same 91 of
> 222 pages, with 20,000 recently dead tuples on those pages. After
> eight partial VACUUMs, the parent's estimate went from 50,000 to
> 49,756, while 7c91a0364fcf went from 30,000 to 1,388. The table had
> 30,000 live rows throughout.

Right. The original difference (50,000 vs 30,000) is the expected change
to harmonize reltuples between ANALYZE and VACUUM. That reltuples then
go down so much from 30,000 to 1,338 is (IMO) a regression in that
change.

> Separately, I ran two tests with your patch on master(76ac7f718d86).
>
> 1. Repeated VACUUMs with no further writes. A full scan counted 44,889
> live rows. I kept a transaction open and ran five ordinary VACUUMs.
> Each scanned 46 of 222 pages and found 5,113 live tuples. Neither
> threshold triggered, so patched and unpatched master gave the same
> estimates:
>
> 44889 -> 40701 -> 37380 -> 34748 -> 32661 -> 31006
>
> count(*) stayed at 44,889. Each drop was modest, but after five runs
> the estimate was 31% low.
>
> 2. Deletes before versus after the last full scan. I arranged for two
> tables to start the partial VACUUMs with the same reltuples of 30,000.
> On A, the full scan had already accounted for 10,000 deletes. On B,
> 10,000 deletes committed just after the full scan. Each partial VACUUM
> scanned 60 of 192 pages and found 168 live tuples on either table, so
> the 2% rule kept both estimates at 30,000 for all five runs. That was
> correct for A, but B had only 20,000 live rows. Unpatched master
> dropped both estimates to 5,062.

I tried to reproduce that but had a hard time. Can you explain in more
detail (or maybe showing SQL commands) what exactly you did so I can
take a look?

Thanks,

Michael

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Ishjaap Singh 2026-12-06 16:25:35 Re: BUG #19936: Planning is slower on 19.0 with many partial indexes on a SQL function
Previous Message Dean Rasheed 2026-12-06 15:00:27 Re: BUG #19929: RETURNING OLD/NEW: segfault when used only inside a hashed subplan

Browse pgsql-hackers by date

  From Date Subject
Next Message Shubh Mehta 2026-12-06 16:23:48 Re: [PATCH] psql: Add tab completion for \dO, \dc and \det
Previous Message Zhijie Hou 2026-12-06 16:02:22 pg_combinebackup copies stale tablespace_map, overriding -T on recovery