Re: PgStat_HashKey padding issue when passed by reference

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Sami Imseih <samimseih@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-09-17T23:32:22Z
Lists: pgsql-hackers
On Tue, Sep 16, 2025 at 02:38:20PM -0500, Sami Imseih wrote:
> 7d85d87f4d5c35 added code to clear the padding bytes with memset
> in anticipation that the key could be changed in the future, in a way
> that padding will be introduced.

Yep.  The argument raised on this thread with the requirement of the
key being passed by reference has made me change my mind, because I
did not thing that valgrind would complain with that.  So yes, I'm
backpedalling a bit.  Sorry for the confusion. 

> So, if we are changing thoughts on
> this, we should add additional comments next to
> ```
> + * NB: We assume that this struct contains no padding.
> ```
> to enforce that the hash stored in objid should be used to
> support additional fields, rather than adding a field directly
> into the key.

Hmm.  Do you have a specific suggestion for enhancement?  I can
think about something like this wording:
"NB: We assume that this struct contains no padding.  The 8 bytes
allocated for the object ID are good enough to ensure the uniqueness
of the hash key, hence the addition of new fields is not recommended."

More suggestions or a better sentence are of course welcome.

> Will help future patch reviews/designs.

Cool, thanks.
--
Michael

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Document and check that PgStat_HashKey has no padding