Re: [PATCH] expand the units that pg_size_pretty supports on output

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Christensen <david(dot)christensen(at)crunchydata(dot)com>, Shinya11(dot)Kato(at)nttdata(dot)com, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] expand the units that pg_size_pretty supports on output
Date: 2021-07-08 13:38:18
Message-ID: CAApHDvpWLS695NiyX=nPTU2EcPYX1kPZNw2Td1dYR0bxy9hjOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

tOn Thu, 8 Jul 2021 at 20:23, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>
> > On Thu, 8 Jul 2021 at 13:31, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> > Here's a patch which I believe makes pg_size_pretty() and
> > pg_size_pretty_numeric() match in regards to negative values.
>
> LGTM, except I think it's worth also making the numeric code not refer
> to bit shifting either.
>
> > Maybe this plus your regression test would be ok to back-patch?
>
> +1
>
> Here's an update with matching updates to the numeric code, plus the
> regression tests.

Looks good.

I gave it a bit of exercise by running pgbench and calling this procedure:

CREATE OR REPLACE PROCEDURE public.test_size_pretty2()
LANGUAGE plpgsql
AS $procedure$
declare b bigint;
begin
FOR i IN 1..1000 LOOP
b := 0 - (random() * 9223372036854775807)::bigint;
if pg_size_pretty(b) <> pg_size_pretty(b::numeric) then
raise notice '%. % != %', b,
pg_size_pretty(b), pg_size_pretty(b::numeric);
end if;
END LOOP;
END;
$procedure$

It ran 8526956 times, so with the loop that's 8.5 billion random
numbers. No variations between the two functions. I got the same
after removing the 0 - to test positive numbers.

If you like, I can push this in my morning, or if you'd rather do it
yourself, please go ahead.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2021-07-08 13:40:36 Re: Enhanced error message to include hint messages for redundant options error
Previous Message Daniel Gustafsson 2021-07-08 13:14:48 Re: Small documentation improvement for ALTER SUBSCRIPTION