pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Document and check that PgStat_HashKey has no padding
Date: Fri, 19 Sep 2025 01:01:55 +0000
Message-ID: <E1uzPVa-001Pd6-22@gemulon.postgresql.org> (raw)

Document and check that PgStat_HashKey has no padding

This change is a tighter rework of 7d85d87f4d5c, which tried to improve
the code so as it would work should PgStat_HashKey gain new fields that
create padding bytes.  However, the previous change is proving to not be
enough as some code paths of pgstats do not pass PgStat_HashKey by
reference (valgrind would warn when padding is added to the structure,
through a new field).

Per discussion, let's document and check that PgStat_HashKey has no
padding rather than try to complicate the code of pgstats so as it is
able to work around that.

This removes a couple of memset(0) calls that should not be required.
While on it, this commit adds a static assertion checking that no
padding is introduced in the structure, by checking that the size of
PgStat_HashKey matches with the sum of the size of all its fields.

The object ID part of the hash key is already 8 bytes, which should be
plenty enough already.  A comment is added to discourage the addition of
new fields.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0t9omat+HVSakJXwTMWvhpYFcAZb41RPWKwrKFUgmAFBQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3cd3a039da7f36b827455a8b9a7068c16b85e15d

Modified Files
--------------
src/backend/utils/activity/pgstat.c       |  5 +----
src/backend/utils/activity/pgstat_shmem.c | 10 ++--------
src/include/utils/pgstat_internal.h       | 17 ++++++++++++++++-
3 files changed, 19 insertions(+), 13 deletions(-)



Message-ID: <E1uzPVa-001Pd6-22@gemulon.postgresql.org>
Permalink:  ../E1uzPVa-001Pd6-22@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uzPVa-001Pd6-22@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Document and check that PgStat_HashKey has no padding
  In-Reply-To: <E1uzPVa-001Pd6-22@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox