From ad7b732a799381518de93a1857e7323d4985c4e6 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Tue, 10 Dec 2024 12:11:35 +0000
Subject: [PATCH v2] Fix and add comments related to pending statistics

The comment linked to the PgStat_TableCounts pending stats mentioning the use of
memcmp() against zeroes to detect whether there are any stats updates to apply
is not true anymore as of 07e9e28b56.

The one linked to memcmp() usage for the PgStat_FunctionCounts pending stats has
probably never been correct.

Adding comments around two other structs to mention that they should also contain
actual event counters because we make use of pg_memory_is_all_zeros() to detect
whether there are any stats updates to apply.
---
 src/include/pgstat.h | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
 100.0% src/include/

diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 59c28b4aca..ce148b9872 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -128,9 +128,6 @@ typedef int64 PgStat_Counter;
 /* ----------
  * PgStat_FunctionCounts	The actual per-function counts kept by a backend
  *
- * This struct should contain only actual event counters, because we memcmp
- * it against zeroes to detect whether there are any pending stats.
- *
  * Note that the time counters are in instr_time format here.  We convert to
  * microseconds in PgStat_Counter format when flushing out pending statistics.
  * ----------
@@ -172,8 +169,9 @@ typedef struct PgStat_BackendSubEntry
 /* ----------
  * PgStat_TableCounts			The actual per-table counts kept by a backend
  *
- * This struct should contain only actual event counters, because we memcmp
- * it against zeroes to detect whether there are any stats updates to apply.
+ * This struct should contain only actual event counters, because we make use
+ * of pg_memory_is_all_zeros() to detect whether there are any stats updates to
+ * apply.
  * It is a component of PgStat_TableStatus (within-backend state).
  *
  * Note: for a table, tuples_returned is the number of tuples successfully
@@ -282,6 +280,11 @@ typedef struct PgStat_ArchiverStats
 	TimestampTz stat_reset_timestamp;
 } PgStat_ArchiverStats;
 
+/*
+ * This struct should contain only actual event counters, because we make use
+ * of pg_memory_is_all_zeros() to detect whether there are any stats updates to
+ * apply.
+ */
 typedef struct PgStat_BgWriterStats
 {
 	PgStat_Counter buf_written_clean;
@@ -290,6 +293,11 @@ typedef struct PgStat_BgWriterStats
 	TimestampTz stat_reset_timestamp;
 } PgStat_BgWriterStats;
 
+/*
+ * This struct should contain only actual event counters, because we make use
+ * of pg_memory_is_all_zeros() to detect whether there are any stats updates to
+ * apply.
+ */
 typedef struct PgStat_CheckpointerStats
 {
 	PgStat_Counter num_timed;
-- 
2.34.1

