Re: Proposal for internal Numeric to Uint64 conversion function. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Proposal for internal Numeric to Uint64 conversion function.
Date
Msg-id 984993.1647029795@sss.pgh.pa.us
Whole thread Raw
In response to Re: Proposal for internal Numeric to Uint64 conversion function.  (Amul Sul <sulamul@gmail.com>)
Responses Re: Proposal for internal Numeric to Uint64 conversion function.  (Greg Stark <stark@mit.edu>)
List pgsql-hackers
Amul Sul <sulamul@gmail.com> writes:
> On Wed, Feb 16, 2022 at 4:50 PM Peter Eisentraut
> <peter.eisentraut@enterprisedb.com> wrote:
>> On 16.02.22 06:00, Amul Sul wrote:
>>> Currently, numeric_pg_lsn is the only one that accepts the Numeric
>>> value and converts to uint64 and that is the reason all the type
>>> conversion code is embedded into it.

>> There are other functions such as numeric_int8() that work similarly.
>> If you are going to refactor, then they should all be treated similarly.
>> I'm not sure if it's going to end up being beneficial.

> Yeah, that's true, I am too not sure if we really need to refactor
> all those; If we want, I can give it a try.

There are several places that call numeric_int8, and right now they
have to go through DirectFunctionCall1, which is ugly and inefficient.
I think a refactoring that exposes some more-convenient API for that
could be useful.  The patch as-presented isn't very compelling for
lack of callers of the new function; but if it were handling the
int64 and uint64 cases alike, and maybe the float8 case too, that
would seem more convincing.  We already expose APIs like int64_to_numeric,
so the lack of similar APIs for the other direction seems odd.

It also feels to me that numeric_pg_lsn(), per se, doesn't belong in
numeric.c.  A pretty direct comparison is numeric_cash(), which is
not in numeric.c but cash.c.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: add checkpoint stats of snapshot and mapping files of pg_logical dir
Next
From: Robert Haas
Date:
Subject: Re: [Proposal] Fully WAL logged CREATE DATABASE - No Checkpoints