Re: NAMEDATALEN increase because of non-latin languages - Mailing list pgsql-hackers

From John Naylor
Subject Re: NAMEDATALEN increase because of non-latin languages
Date
Msg-id CAFBsxsFmJGiNpWkvdmLGD-YGt6hU_xRxcLJEz+JHJ4=C8qvoaQ@mail.gmail.com
Whole thread Raw
In response to Re: NAMEDATALEN increase because of non-latin languages  (Andres Freund <andres@anarazel.de>)
Responses Re: NAMEDATALEN increase because of non-latin languages
List pgsql-hackers
On Tue, Jul 19, 2022 at 10:57 PM Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
> On 2022-07-19 14:30:34 +0700, John Naylor wrote:
> > I'm thinking where the first few attributes are fixed length, not null, and
> > (because of AIX) not double-aligned, we can do a single memcpy on multiple
> > columns at once. That will still be a common pattern after namedata is
> > varlen. Otherwise, use helper functions/macros similar to the above but
> > instead of passing a tuple descriptor, use info we have at compile time.
>
> I think that might be over-optimizing things. I don't think we do these
> conversions at a rate that's high enough to warrant it - the common stuff
> should be in relcache etc.  It's possible that we might want to optimize the
> catcache case specifically - but that'd be more optimizing memory usage than
> "conversion" imo.

Okay, here is a hackish experiment that applies on top of v2 but also invalidates some of that earlier work. Since there is already a pg_cast.c, I demoed a new function there which looks like this:

void
Deform_pg_cast_tuple(Form_pg_cast pg_cast_struct, HeapTuple pg_cast_tuple, TupleDesc pg_cast_desc)
{
    Datum values[Natts_pg_cast];
    bool isnull[Natts_pg_cast];

    heap_deform_tuple(pg_cast_tuple, pg_cast_desc, values, isnull);

    pg_cast_struct->oid = DatumGetObjectId(values[Anum_pg_cast_oid - 1]);
    pg_cast_struct->castsource = DatumGetObjectId(values[Anum_pg_cast_castsource - 1]);
    pg_cast_struct->casttarget = DatumGetObjectId(values[Anum_pg_cast_casttarget - 1]);
    pg_cast_struct->castfunc = DatumGetObjectId(values[Anum_pg_cast_castfunc - 1]);
    pg_cast_struct->castcontext = DatumGetChar(values[Anum_pg_cast_castcontext - 1]);
    pg_cast_struct->castmethod = DatumGetChar(values[Anum_pg_cast_castmethod - 1]);
}

For the general case we can use pg_*_deform.c or something like that, with extern declarations in the main headers. To get this to work, I had to add a couple pointless table open/close calls to get the tuple descriptor, since currently the whole tuple is stored in the syscache, but that's not good even as a temporary measure. Storing the full struct in the syscache is a good future step, as noted upthread, but to get there without a bunch more churn, maybe the above function can copy the tuple descriptor into a local stack variable from an expanded version of schemapg.h. Once the deformed structs are stored in caches, I imagine most of the times we want to deform are when we have the table open, and we can pass the descriptor as above without additional code.

--
John Naylor
EDB: http://www.enterprisedb.com
Attachment

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: pg_tablespace_location() failure with allow_in_place_tablespaces
Next
From: Dean Rasheed
Date:
Subject: Re: [PATCH] Introduce array_shuffle() and array_sample()