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

Поиск
Список
Период
Сортировка
От Dean Rasheed
Тема Re: Add support for unit "B" to pg_size_pretty()
Дата
Msg-id CAEZATCVvKspBjEzxj-EuqFkvjWzdyu+ThBCh4a+QnWmFd3VRUQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Add support for unit "B" to pg_size_pretty()  (David Rowley <dgrowleyml@gmail.com>)
Ответы Re: Add support for unit "B" to pg_size_pretty()  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-hackers
On Thu, 2 Mar 2023 at 19:58, David Rowley <dgrowleyml@gmail.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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alexander Korotkov
Дата:
Сообщение: Re: POC: Lock updated tuples in tuple_update() and tuple_delete()
Следующее
От: Kirk Wolak
Дата:
Сообщение: Re: proposal: psql: show current user in prompt