Re: Add support for unit "B" to pg_size_pretty()
| От | David Rowley |
|---|---|
| Тема | Re: Add support for unit "B" to pg_size_pretty() |
| Дата | |
| Msg-id | CAApHDvpzxuo5F8-zbDoK7ZFmVjMbvVK3XQjNcZZuGcMhBc0V5w@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Add support for unit "B" to pg_size_pretty() (Peter Eisentraut <peter.eisentraut@enterprisedb.com>) |
| Ответы |
Re: Add support for unit "B" to pg_size_pretty()
Re: Add support for unit "B" to pg_size_pretty() |
| Список | pgsql-hackers |
On Mon, 27 Feb 2023 at 21:34, Peter Eisentraut
<peter.eisentraut@enterprisedb.com> wrote:
>
> On 22.02.23 03:39, David Rowley wrote:
> > I think you'll need to find another way to make the aliases work.
> > Maybe another array with the name and an int to reference the
> > corresponding index in size_pretty_units.
>
> Ok, here is a new patch with a separate table of aliases. (Might look
> like overkill, but I think the "PiB" etc. example you had could actually
> be a good use case for this as well.)
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.
Apart from that, the patch looks fine.
David
В списке pgsql-hackers по дате отправления: