Re: Import Statistics in postgres_fdw before resorting to sampling.

From: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
To: Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers(at)postgresql(dot)org, jkatz(at)postgresql(dot)org, nathandbossart(at)gmail(dot)com
Subject: Re: Import Statistics in postgres_fdw before resorting to sampling.
Date: 2026-04-30 18:04:22
Message-ID: CADkLM=eLnEf3aFSqDYgHZ8s4MmOsNLicei4HKAY_8Kxjpt2yaw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> > AFAICS, postgres_fdw's subsequent uses of those strings only need
> > them to be nul-terminated C strings, so strncpy's property of
> > zero-filling the whole buffer is not needed here. I recommend
> > s/strncpy/strlcpy/.
>
> Seems like a good idea.
>
> > It's probably also appropriate to think about using pg_mbcliplen()
> > to ensure that this code doesn't result in a broken multibyte
> > character.
>
> Will do.
>
> I am currently overseas and will be attending an event this week, so I
> will work on this after returning home. In the meantime, I created an
> entry for it in the open items list.
>
> Thanks!

I've attached 2 different fixes.

The first one swtiches to pg_mbcliplen+memcpy, which is probably overkill
but better safe than sorry.

The second gets rid of the string buffers entirely, and instead frees the
nested object.

I have no preference between the two, though I suspect that the nested-free
solution will be preferred by the community.

Attachment Content-Type Size
v1-0001-Replace-strncpy-with-pg_mbcliplen-plus-memcpy.patch text/x-patch 1.8 KB
v1-0001-Replace-name-buffers-from-RemoteAttributeMapping-.patch text/x-patch 3.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tristan Partin 2026-04-30 18:19:40 Interest in hosting a buildfarm animal
Previous Message Masahiko Sawada 2026-04-30 17:53:48 Re: Fix race condition in XLogLogicalInfo and ProcSignal initialization.