pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Consistently use PageGetExactFreeSpace() in pgstattuple.
Date: Mon, 09 Sep 2024 18:34:17 +0000
Message-ID: <E1snjDN-000L0r-Hy@gemulon.postgresql.org> (raw)

Consistently use PageGetExactFreeSpace() in pgstattuple.

Previously this code used PageGetHeapFreeSpace on heap pages,
and usually used PageGetFreeSpace on index pages (though for some
reason GetHashPageStats used PageGetExactFreeSpace instead).
The difference is that those functions subtract off the size of
a line pointer, and PageGetHeapFreeSpace has some additional
rules about returning zero if adding another line pointer would
require exceeding MaxHeapTuplesPerPage.  Those things make sense
when testing to see if a new tuple can be put on the page, but
they seem pretty strange for pure statistics collection.

Additionally, statapprox_heap had a special rule about counting
a "new" page as being fully available space.  This also seems
strange, because it's not actually usable until VACUUM or some
such process initializes the page.  Moreover, it's inconsistent
with what pgstat_heap does, which is to count such a page as
having zero free space.  So make it work like pgstat_heap, which
as of this patch unconditionally calls PageGetExactFreeSpace.

This is more of a definitional change than a bug fix, so no
back-patch.  The module's documentation doesn't define exactly
what "free space" means either, so we left that as-is.

Frédéric Yhuel, reviewed by Rafia Sabih and Andreas Karlsson.

Discussion: https://postgr.es/m/3a18f843-76f6-4a84-8cca-49537fefa15d@dalibo.com

Branch
------
master

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

Modified Files
--------------
contrib/pgstattuple/pgstatapprox.c | 9 +--------
contrib/pgstattuple/pgstatindex.c  | 2 +-
contrib/pgstattuple/pgstattuple.c  | 6 +++---
3 files changed, 5 insertions(+), 12 deletions(-)



Message-ID: <E1snjDN-000L0r-Hy@gemulon.postgresql.org>
Permalink:  ../E1snjDN-000L0r-Hy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1snjDN-000L0r-Hy@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Consistently use PageGetExactFreeSpace() in pgstattuple.
  In-Reply-To: <E1snjDN-000L0r-Hy@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox