Re: Clear padding in PgStat_HashKey keys - Mailing list pgsql-hackers

From Jelte Fennema-Nio
Subject Re: Clear padding in PgStat_HashKey keys
Date
Msg-id CAGECzQS37h0twutb=kkS6v0rSnQ0vWxhVncqVNYoOTsv6gOmcw@mail.gmail.com
Whole thread Raw
Responses Re: Clear padding in PgStat_HashKey keys
List pgsql-hackers
On Mon, 4 Nov 2024 at 08:25, Michael Paquier <michael@paquier.xyz> wrote:
> Perhaps it would be simpler to use a {0} like anywhere else for
> PgStat_HashKey in pgstat_fetch_entry() and pgstat_drop_entry(), then
> initialize the individual fields?

{0} doesn't clear padding, it only sets all the fields to 0.

So in many places we use memset or MemSet to clear the padding already:

rg 'memset.*key' -S | wc -l
31

And even using memset in this manner isn't a standards compliant way
of handling this problem[0]. But it seems to have worked well enough
in practice.

Whether it's worth changing this now or only when we actually
introduce padding is another question though. But the code itself and
reasoning is sensible imo.

[0]:
https://www.postgresql.org/message-id/flat/8c1e502a337e9557278f31abf877c321%40anastigmatix.net#4113241930633758cdbc22f49365806f



pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: general purpose array_sort
Next
From: Bertrand Drouvot
Date:
Subject: Re: Clear padding in PgStat_HashKey keys