Re: NAMEDATALEN increase because of non-latin languages

Поиск
Список
Период
Сортировка
От John Naylor
Тема Re: NAMEDATALEN increase because of non-latin languages
Дата
Msg-id CAFBsxsEcWQeqi1oHMQx-cz+zvUc2yEOTrp-uLqPD6bAKGHZGEA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: NAMEDATALEN increase because of non-latin languages  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: NAMEDATALEN increase because of non-latin languages  (Andres Freund <andres@anarazel.de>)
Список pgsql-hackers

On Thu, Jun 23, 2022 at 9:27 PM Robert Haas <robertmhaas@gmail.com> wrote:
>
> I'm not sure whether your idea of creating translator functions is a
> good one or not, but it doesn't seem too crazy. It'd be like a special
> purpose tuple deformer.
>
> deform_pg_class_tuple(&pg_class_struct, pg_class_tuple);
>
> The code in there could be automatically generated statements that
> maybe look like this:
>
> memcpy(&struct.relnamespace, tuple + Aoffset_pg_class_relnamespace,
> sizeof(Oid));

I've made a small step in this direction.

0001 is just boilerplate, same as v1
0002 teaches Catalog.pm to export both C attr name and SQL attr name, so we can use "sizeof".
0003 generates static inline functions that work the same as the current GETSTRUCT macro, i.e. just cast to the right pointer and return it.
0004 generates a function for pg_cast that memcpys to a passed struct, for demonstration.

Here's the full deforming function generated for pg_cast. In English, the current offset is the previous offset plus the previous type length, plus any alignment padding suitable for the current type (there is none here, so the alignment aspect is not tested). I'm hoping something like this will be sufficient for what's in the current structs, but of course will need additional work when expanding those to include pointers to varlen attributes. I've not yet inspected the emitted assembly language, but regression tests pass.

static inline void
Deform_pg_cast_tuple(Form_pg_cast pg_cast_struct, char * pg_cast_tuple)
{
#define Aoff_pg_cast_oid 0
memcpy(&pg_cast_struct->oid, pg_cast_tuple + Aoff_pg_cast_oid, sizeof(Oid));

#define Aoff_pg_cast_castsource att_align_nominal(Aoff_pg_cast_oid + sizeof(Oid), 'i')
memcpy(&pg_cast_struct->castsource, pg_cast_tuple + Aoff_pg_cast_castsource, sizeof(Oid));

#define Aoff_pg_cast_casttarget att_align_nominal(Aoff_pg_cast_castsource + sizeof(Oid), 'i')
memcpy(&pg_cast_struct->casttarget, pg_cast_tuple + Aoff_pg_cast_casttarget, sizeof(Oid));

#define Aoff_pg_cast_castfunc att_align_nominal(Aoff_pg_cast_casttarget + sizeof(Oid), 'i')
memcpy(&pg_cast_struct->castfunc, pg_cast_tuple + Aoff_pg_cast_castfunc, sizeof(Oid));

#define Aoff_pg_cast_castcontext att_align_nominal(Aoff_pg_cast_castfunc + sizeof(Oid), 'c')
memcpy(&pg_cast_struct->castcontext, pg_cast_tuple + Aoff_pg_cast_castcontext, sizeof(char));

#define Aoff_pg_cast_castmethod att_align_nominal(Aoff_pg_cast_castcontext + sizeof(char), 'c')
memcpy(&pg_cast_struct->castmethod, pg_cast_tuple + Aoff_pg_cast_castmethod, sizeof(char));
}

Here's an example of the changes done in the call sites. For the rest of the catalogs, perhaps many of them can be done mechanically. I still anticipate a lot of manual work. Note that GETSTRUCT_MEMCPY is just temporary scaffolding to distinguish from just returning a pointer, and is not proposed for commit.

-               Form_pg_cast castForm = GETSTRUCT(pg_cast, tuple);
+               FormData_pg_cast castForm;
                CoercionContext castcontext;
 
+               GETSTRUCT_MEMCPY(pg_cast, &castForm, tuple);
+
                /* convert char value for castcontext to CoercionContext enum */
-               switch (castForm->castcontext)
+               switch (castForm.castcontext)

--
John Naylor
EDB: http://www.enterprisedb.com
Вложения

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

Предыдущее
От: Morris de Oryx
Дата:
Сообщение: System column support for partitioned tables using heap
Следующее
От: Andres Freund
Дата:
Сообщение: Re: NAMEDATALEN increase because of non-latin languages