pgstattuple: fix free space calculation

Frédéric Yhuel <frederic.yhuel@dalibo.com>

From: Frédéric Yhuel <frederic.yhuel@dalibo.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-08-22T08:10:53Z
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.

Attachments

Hello,

I think that pgstattuple should use PageGetExactFreeSpace() instead of 
PageGetHeapFreeSpace() or PageGetFreeSpace(). The latter two compute the 
free space minus the space of a line pointer. They are used like this in 
the rest of the code (heapam.c):

pagefree = PageGetHeapFreeSpace(page);

if (newtupsize > pagefree) { we need a another page for the tuple }

... so it makes sense to take the line pointer into account in this context.

But it in the pgstattuple context, I think we want the exact free space.

I have attached a patch.

Best regards,
Frédéric