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

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: 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-06 11:39:13
Message-ID: CAEZATCWgQgSEU_vpVbxdruqJnhiN8X57GC6x83SyAEUhkVFmYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 6 Jul 2021 at 10:20, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
> I made another pass over this and ended up removing the doHalfRound
> field in favour of just doing rounding based on the previous
> bitshifts.
>

When I first read this:

+ /* half-round until we get down to unitBits */
+ while (rightshifts++ < unit->unitBits)
+ size = half_rounded(size);

it looked to me like it would be invoking half_rounded() multiple
times, which raised alarm bells because that would risk rounding the
wrong way. Eventually I realised that by the time it reaches that,
rightshifts will always equal unit->unitBits or unit->unitBits - 1, so
it'll never do more than one half-round, which is important.

So perhaps using doHalfRound would be clearer, but it could just be a
local variable tracking whether or not it's the first time through the
loop.

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2021-07-06 11:48:51 Re: [PATCH] Use optimized single-datum tuplesort in ExecSort
Previous Message Bharath Rupireddy 2021-07-06 11:37:04 Re: Can a child process detect postmaster death when in pg_usleep?