Re: pgstattuple: fix free space calculation

Andreas Karlsson <andreas@proxel.se>

From: Andreas Karlsson <andreas@proxel.se>
To: Rafia Sabih <rafia.pghackers@gmail.com>, Frédéric Yhuel <frederic.yhuel@dalibo.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-08-23T11:11:38Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Consistently use PageGetExactFreeSpace() in pgstattuple.

On 8/23/24 12:02 PM, Rafia Sabih wrote:> On the other hand, this got me 
thinking about the purpose of this space > information.
> If we want to understand that there's still some space for the tuples in 
> a page, then using PageGetExactFreeSpace is not doing justice in case of 
> heap page, because we will not be able to add any more tuples there if 
> there are already MaxHeapTuplesPerPage tuples there.

I think the new behavior is the more useful one since what if someone 
wants to know the free space since they want to insert two tuples and 
not just one? I do not think the function should assume that the only 
reason someone would want to know the size is because they want to 
insert exactly one new tuple.

I am less certain about what the right behavior on pages where we are 
out of line pointers should be but I am leaning towards that the new 
behvior is better than the old but can see a case for either.

Tested the patch and it works as advertised.

Andreas