Thread: Thinko in pgstat_build_snapshot()

Thinko in pgstat_build_snapshot()

From
Etsuro Fujita
Date:
While working on something else I noticed $SUBJECT: we are allocating
more memory than necessary and copying more data than necessary
because we specify the wrong PgStat_KindInfo member as the size
argument for MemoryContextAlloc and memcpy.  This could become
problematic if snapshotting a very large number of variables stats, so
I fixed it.  Attached is a patch for that.

Best regards,
Etsuro Fujita

Attachment

Re: Thinko in pgstat_build_snapshot()

From
Heikki Linnakangas
Date:
On 30/03/2025 13:23, Etsuro Fujita wrote:
> While working on something else I noticed $SUBJECT: we are allocating
> more memory than necessary and copying more data than necessary
> because we specify the wrong PgStat_KindInfo member as the size
> argument for MemoryContextAlloc and memcpy.  This could become
> problematic if snapshotting a very large number of variables stats, so
> I fixed it.  Attached is a patch for that.

Good catch. Patch looks good to me at quick glance.

-- 
Heikki Linnakangas
Neon (https://neon.tech)



Re: Thinko in pgstat_build_snapshot()

From
Gurjeet Singh
Date:
On Sun, Mar 30, 2025 at 4:31 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>
> On 30/03/2025 13:23, Etsuro Fujita wrote:
> > While working on something else I noticed $SUBJECT: we are allocating
> > more memory than necessary and copying more data than necessary
> > because we specify the wrong PgStat_KindInfo member as the size
> > argument for MemoryContextAlloc and memcpy.  This could become
> > problematic if snapshotting a very large number of variables stats, so
> > I fixed it.  Attached is a patch for that.
>
> Good catch. Patch looks good to me at quick glance.

+1 on both counts.

Best regards,
Gurjeet
http://Gurje.et