From: | Erik Nordström <erik(at)timescale(dot)com> |
---|---|
To: | Sami Imseih <samimseih(at)gmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Relstats after VACUUM FULL and CLUSTER |
Date: | 2025-05-23 13:18:04 |
Message-ID: | CACAa4V+vUyKwkqs8O_dqR736YOZoKaGQJFQZikAB8WSYyFzbrg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi Sami,
Your patch should correct the problem. However, given that this function is
part of the tableam API, I am wondering if the fix shouldn't be outside
heap's copy_for_cluster implementation? I guess it depends on the semantics
of num_tuples, but the cluster code seems to allude to interpreting
num_tuples as the number of non-removable tuples. If you subtract recently
dead from that number within the heap implementation, then it will no
longer reflect non-removable tuples and the log message in the cluster
function "found %.0f removable, %.0f nonremovable row versions" will no
longer be correct.
Surprisingly, tableam.h does not document the num_tuples parameter in the
table_relation_copy_for_cluster() function although all other output
parameters are documented. So, it is not clear what the intended semantics
are. Maybe other hackers on the mailing list have opinions on how to
interpret num_tuples?
In any case, assuming num_tuples is supposed to return non-removable
tuples, then the fix should be to subtract recently dead tuples when
updating pg_class.reltuples. Other TAM's need to treat num_tuples as
non-removable tuples as well, and update recently dead if applicable.
I am attaching a patch with these changes, while also including the
isolation test in that patch.
Regards,
Erik
On Thu, May 22, 2025 at 10:42 PM Sami Imseih <samimseih(at)gmail(dot)com> wrote:
> > In both cases, he recently dead tuples must be copied to the table or
> index, but
> > they should not be counted towards reltuples. So, I think we need to fix
> this in
> > heapam_relation_copy_for_cluster by probably subtracting
> > tups_recently_dead from num_tuples ( which is the value set in
> > pg_class.reltuples )
> > after we process all the tuples, which looks like the best fix to me.
>
> something like the attached.
>
> --
> Sami Imseih
> Amazon Web Services (AWS)
>
Attachment | Content-Type | Size |
---|---|---|
v1-0001-Fix-reltuples-stats-after-VACUUM-FULL-and-CLUSTER.patch | text/x-patch | 6.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | jian he | 2025-05-23 13:19:07 | Disallow concurrent ALTER DOMAIN and DROP DOMAIN |
Previous Message | jian he | 2025-05-23 12:47:34 | Re: pg18: Virtual generated columns are not (yet) safe when superuser selects from them |