RE: Use correct macro for accessing offset numbers.

From: li carol <carol(dot)li2025(at)outlook(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Kirill Reshke <reshkekirill(at)gmail(dot)com>
Cc: Roman Khapov <rkhapov(at)yandex-team(dot)ru>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Use correct macro for accessing offset numbers.
Date: 2026-01-12 05:36:15
Message-ID: TYSPR01MB6650128F7CCEBE1C809AE51E8181A@TYSPR01MB6650.apcprd01.prod.exchangelabs.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> On Sun, Jan 11, 2026 at 04:58:39PM +0500, Kirill Reshke wrote:
> > Maybe, I have stopped some more cases, in v2-0001
>
> Right. It's true that we could be more consistent for all these based on their
> base type, some of them, particularly in the GIN code now, caring about using
> the correct macro. It may be a good occasion to double-check the whole tree
> for similar holes based on unsigned types.
> --
> Michael

Hi Kirill, Roman, and Michael,
While double-checking the tree for similar holes as Michael suggested, I noticed a couple more inconsistencies in contrib/pageinspect/ginfuncs.c where we are using signed macros for unsigned types.
Specifically, in gin_page_opaque_info, we use Int32GetDatum for maxoff:

values[1] = Int32GetDatum(opaq->maxoff);

Since maxoff is of type OffsetNumber (uint16), this seems to be the exact same pattern Kirill is addressing in other parts of the GIN code. Although it is widened to int32 here, for the sake of consistency, it should probably be using a 16-bit or unsigned macro.

Similarly, in gin_metapage_info, tailFreeSize (which is defined as uint32 in GinMetaPageData) is also converted using Int32GetDatum:

values[2] = Int32GetDatum(metadata->tailFreeSize);

It might be better to include these cleanups in the next version of the patch to ensure all pageinspect GIN functions follow the same standard.

Best regards,
Yuan Li(carol)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuro Yamada 2026-01-12 05:39:21 Re: [PATCH] psql: add \dcs to list all constraints
Previous Message Peter Smith 2026-01-12 05:29:18 Re: Proposal: Conflict log history table for Logical Replication