Re: PgStat_HashKey padding issue when passed by reference

From: Andres Freund <andres(at)anarazel(dot)de>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Sami Imseih <samimseih(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PgStat_HashKey padding issue when passed by reference
Date: 2025-09-08 16:08:12
Message-ID: nkhswvbuermxehrv6b76vsi4c3aevdtohui7gx3vv45msjgdqf@ijxvn4kcjdsd
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2025-09-08 10:25:13 +0900, Michael Paquier wrote:
> On Sat, Sep 06, 2025 at 10:35:58AM +0900, Michael Paquier wrote:
> > One idea would be, for example, that keys used with simplehash should
> > never have any padding at all, and we could force a check in the shape
> > of a static assertion to force a failure when attempting to compile
> > code that attempts to do so. That would give us a way to check in a
> > broader way if some code path do that currently, scaling better with
> > the expectations we could have in the whole tree or even out-of-core
> > extension code.
>
> Doing some research here, I have noticed this one:
> https://en.cppreference.com/w/cpp/types/has_unique_object_representations.html
>
> I was also wondering about some use of pg_attribute_packed() here, or
> perhaps enforce a check based on offsetof() and the structure size,
> but I doubt that any of that would be really portable across the
> buildfarm.
>
> Another idea would be to make sure that the sizeof() of the structure
> matches with the sum of the sizeof() for the individual fields in it.
> That's cumbersome to rely on, still simpler. Perhaps we could do
> something among these lines for pgstat_shmem.c, or just document that
> the structure should never have any padding.

I'd just add a comment mentioning that any padding bytes should be avoided.

Greetings,

Andres

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mircea Cadariu 2025-09-08 16:34:00 Re: [BUG] temporary file usage report with extended protocol and unnamed portals
Previous Message Andres Freund 2025-09-08 15:55:29 Re: postmaster uses more CPU in 18 beta1 with io_method=io_uring