Re: Making aggregate deserialization (and WAL receive) functions slightly faster - Mailing list pgsql-hackers

From David Rowley
Subject Re: Making aggregate deserialization (and WAL receive) functions slightly faster
Date
Msg-id CAApHDvr7AC7hWy4Es=D3pE3aiQkczD-ibaPxq+_WMbuKo0N8mQ@mail.gmail.com
Whole thread Raw
In response to Re: Making aggregate deserialization (and WAL receive) functions slightly faster  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Making aggregate deserialization (and WAL receive) functions slightly faster
List pgsql-hackers
Thanks for taking a look at this.

On Wed, 4 Oct 2023 at 16:57, Michael Paquier <michael@paquier.xyz> wrote:
> +       buf.len = VARSIZE_ANY_EXHDR(sstate);
> +       buf.maxlen = 0;
> +       buf.cursor = 0;
>
> Perhaps it would be worth hiding that in a macro defined in
> stringinfo.h?

The original patch had a new function in stringinfo.c which allowed a
StringInfoData to be initialised from an existing string with some
given length.  Tom wasn't a fan of that because there wasn't any
protection against someone trying to use the given StringInfoData and
then calling appendStringInfo to append another string. That can't be
done in this case as we can't repalloc the VARDATA_ANY(state) pointer
due to it not pointing directly to a palloc'd chunk.  Tom's complaint
seemed to be about having a reusable function which could be abused,
so I modified the patch to remove the reusable code.  I think your
macro idea in stringinfo.h would put the patch in the same position as
it was initially.

It would be possible to do something like have maxlen == -1 mean that
the StringInfoData.data field isn't being managed internally in
stringinfo.c and then have all the appendStringInfo functions check
for that, but I really don't want to add overhead to everything that
uses appendStringInfo just for this.

David



pgsql-hackers by date:

Previous
From: "Drouvot, Bertrand"
Date:
Subject: Re: Synchronizing slots from primary to standby
Next
From: Andrei Lepikhov
Date:
Subject: Re: Removing unneeded self joins