Re: Use correct macro for accessing offset numbers. - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Use correct macro for accessing offset numbers.
Date
Msg-id 97f9375a-be61-4272-a44d-408337fe8fa6@eisentraut.org
Whole thread
In response to Re: Use correct macro for accessing offset numbers.  (Michael Paquier <michael@paquier.xyz>)
List pgsql-hackers
On 14.01.26 09:08, Michael Paquier wrote:
> On Mon, Jan 12, 2026 at 01:51:10PM +0500, Kirill Reshke wrote:
>> PFA v3 with fixes for signed usage across the tree, with my new
>> findings and suggestions from thread
> 
> Note that the change in get_opfamily_member() is not right based on
> the type of "strategy".  The rest was OK, so done.

The thread [0] is proposing a patch to change these things in the 
opposite direction, effectively reverting commit 6dcfac9696c.

I think the premise of the patch in this thread is incorrect.  You have 
changed

     Int16GetDatum(offset)

to

     UInt16GetDatum(offset)

because the variable offset is of type OffsetNumber, which is uint16.

But that is not the meaning of the "UInt16" in UInt16GetDatum(), at 
least that's the argument being made in the other thread.

These values end up being converted to an output parameter of type 
smallint, and the output function int2out uses DatumGetInt16() to 
convert its argument.  So the *GetDatum() function should match that, so 
we should use Int16GetDatum().

The real problem here is that offset values that are uint32 are being 
output via the SQL type smallint, which can't handle the whole set of 
values, but this is probably not a problem in practice.


[0]: 
https://www.postgresql.org/message-id/flat/CALdSSPhFyb9qLSHee73XtZm1CBWJNo9+JzFNf-zUEWCRW5yEiQ@mail.gmail.com




pgsql-hackers by date:

Previous
From: Fabrice Chapuis
Date:
Subject: question on visibility map
Next
From: Etsuro Fujita
Date:
Subject: Re: Use-after-free issue in postgres_fdw