Re: pg_walinspect float4/float8 confusion

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_walinspect float4/float8 confusion
Date: 2022-09-09 03:51:17
Message-ID: CALj2ACXbjijc3pwM+=dS7+Jth2-3Pwyx691iVMwZC26hkrj_nQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Sep 8, 2022 at 5:23 PM Peter Eisentraut
<peter(dot)eisentraut(at)enterprisedb(dot)com> wrote:
>
> The pg_walinspect function pg_get_wal_stats() has output arguments
> declared as float4 (count_percentage, record_size_percentage, etc.), but
> the internal computations are all done in type double. Is there a
> reason why this is then converted to float4 for output? It probably
> doesn't matter in practice, but it seems unnecessarily confusing. Or at
> least add a comment so it doesn't look like an accident. Also compare
> with pgstattuple, which uses float8 in its SQL interface for similar data.

Thanks for finding this. There's no specific reason as such. However,
it's good to be in sync with what code does internally and what it
exposes to the users. pg_walinspect uses double data type (double
precision floating point number) for internal calculations and cuts it
down to single precision floating point number float4 to the users.
Attaching a patch herewith. I'm not sure if this needs to be
backported, if at all, we were to, IMO it should be backported to
reduce the code diff.

While on, I found that pgstattuple uses uint64 for internal percentile
calculations as opposed to double data type for others. Attaching a
small patch to fix it.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v1-0001-Use-float8-datatype-for-percentiles-in-pg_walinsp.patch application/octet-stream 5.7 KB
v1-0001-Use-double-datatype-for-percentiles-in-pgstattupl.patch application/octet-stream 1.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2022-09-09 04:36:55 Re: pg15b3: recovery fails with wal prefetch enabled
Previous Message bt22kawamotok 2022-09-09 02:18:13 [PATCH]Feature improvement for MERGE tab completion