Re: Add support for unit "B" to pg_size_pretty()

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add support for unit "B" to pg_size_pretty()
Date: 2023-03-02 20:32:26
Message-ID: CAEZATCVvKspBjEzxj-EuqFkvjWzdyu+ThBCh4a+QnWmFd3VRUQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 2 Mar 2023 at 19:58, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>
> I think I'd prefer to see the size_bytes_unit_alias struct have an
> index into size_pretty_units[] array. i.e:
>
> struct size_bytes_unit_alias
> {
> const char *alias; /* aliased unit name */
> const int unit_index; /* corresponding size_pretty_units element */
> };
>
> then the pg_size_bytes code can be simplified to:
>
> /* If not found, look in the table of aliases */
> if (unit->name == NULL)
> {
> for (const struct size_bytes_unit_alias *a = size_bytes_aliases;
> a->alias != NULL; a++)
> {
> if (pg_strcasecmp(strptr, a->alias) == 0)
> {
> unit = &size_pretty_units[a->unit_index];
> break;
> }
> }
> }
>
> which saves having to have the additional and slower nested loop code.
>

Hmm, I think it would be easier to just have a separate table for
pg_size_bytes(), rather than reusing pg_size_pretty()'s table. I.e.,
size_bytes_units[], which would only need name and multiplier columns
(not round and limit). Done that way, it would be easier to add other
units later (e.g., non-base-2 units).

Also, it looks to me as though the doc change is for pg_size_pretty()
instead of pg_size_bytes().

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kirk Wolak 2023-03-02 20:45:10 Re: proposal: psql: show current user in prompt
Previous Message Alexander Korotkov 2023-03-02 20:16:41 Re: POC: Lock updated tuples in tuple_update() and tuple_delete()