Re: Proposal for internal Numeric to Uint64 conversion function.

From: Amul Sul <sulamul(at)gmail(dot)com>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Proposal for internal Numeric to Uint64 conversion function.
Date: 2022-04-22 12:26:40
Message-ID: CAAJ_b969U7YH2m=fB2YALyqZm-OXyt3gPEej9A+5m5f+aTa89A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 18, 2022 at 1:17 AM Greg Stark <stark(at)mit(dot)edu> wrote:
>
> On Fri, 11 Mar 2022 at 15:17, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >
> > Amul Sul <sulamul(at)gmail(dot)com> writes:
>
> > > 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.
> >
> > The patch as-presented isn't very compelling for
> > lack of callers of the new function
>
> Tom, are you saying you think we're not interested in just adding this
> function unless it's part of this refactoring?
>
> Amul, do you think if we did numeric_to_int64/numeric_to_uint64 as a
> refactored API and a second patch that made numeric_pg_lsn and other
> consumers use it it would clean up the code significantly?

Sorry for the long absence.

Yes, I think we can do cleanup to some extent. Attaching the
following patches that first intend to remove DirectFunctionCall as
much as possible:

0001:
Refactors and moves numeric_pg_lsn to pg_lsn.c file. Function gut is
in numeric.c as numeric_to_uint64_type() generalised function that can
be used elsewhere too.

0002:
Does little more cleanup to pg_lsn.c file -- replace few
DirectFunctionCall1() by the numeric_to_uint64_type().

0003:
Refactors numeric_int8() function and replace few
DirectFunctionCall1() to numeric_int8 by the newly added
numeric_to_int64() and numeric_to_int64_type().
numeric_to_int64_type() version can be called only when you want to
refer to the specific type name in the error message like
numeric_to_uint64_type, e.g.MONEY type.

0004:
Adding float8_to_numeric and numeric_to_float8 by refactoring
float8_numeric and numeric_float8 respectively. I am a bit confused
about whether the type should be referred to as float8 or double.
Replaces a few DirectFunctionCall() calls by these c functions.

0005:
This one replaces all DirectFunctionCall needed for the numeric
arithmetic operations.

Regards,
Amul

Attachment Content-Type Size
v2-0005-Call-numeric-arithmetic-functions-directly.patch application/x-patch 13.7 KB
v2-0002-More-cleanup-to-pg_lsn.c.patch application/x-patch 1.7 KB
v2-0001-Move-numeric_pg_lsn-to-pg_lsn.c-file.patch application/x-patch 3.4 KB
v2-0004-Add-float8_to_numeric-and-numeric_to_float8-by-co.patch application/x-patch 7.0 KB
v2-0003-Add-numeric_to_int64-by-refactoring-numeric_int8.patch application/x-patch 4.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2022-04-22 13:15:31 Re: pgsql: Allow db.schema.table patterns, but complain about random garbag
Previous Message Gilles Darold 2022-04-22 09:57:05 Re: [Proposal] vacuumdb --schema only