On Fri, 7 Nov 2025 at 07:26, Peter Eisentraut <[email protected]> wrote:
>
> On 06.11.25 13:17, Heikki Linnakangas wrote:
> >> @@ -476,7 +476,7 @@ CatCachePrintStats(int code, Datum arg)
> >>
> >>          if (cache->cc_ntup == 0 && cache->cc_searches == 0)
> >>              continue;            /* don't print unused caches */
> >> -        elog(DEBUG2, "catcache %s/%u: %d tup, %ld srch, %ld+%ld=%ld
> >> hits, %ld+%ld=%ld loads, %ld invals, %d lists, %ld lsrch, %ld lhits",
> >> +        elog(DEBUG2, "catcache %s/%u: %d tup, %" PRIu64 " srch, %"
> >> PRIu64 "+%" PRIu64 "=%" PRIu64 " hits, %" PRIu64 "+%" PRIu64 "=%"
> >> PRIu64 " loads, %" PRIu64 " invals, %d lists, %" PRIu64 " lsrch, %"
> >> PRIu64 " lhits",
> >>               cache->cc_relname,
> >>               cache->cc_indexoid,
> >>               cache->cc_ntup,
> >
> > Unfortunately PRIu64 makes these much longer and less readable. I don't
> > think there's much we can do about that though. Perhaps split the format
> > string to multiple lines?
>
> You could also use unsigned long long int for these, to make the format
> strings more readable.

I couldn't really decide on what's best here. I'd personally rather be
more explicit about the width of the type by using uint64, but on the
other hand, I don't know of any realistic modern hardware/compiler
combination where unsigned long long isn't 64-bit. Certainly, the
format string is easier to read with %llu.

v2-0001 wraps the format string as suggested by Heikki, v3-0001 uses
unsigned long long as suggested by Peter.

v2-0002 is updated to use size_t instead of Size, per Heikki

Any further opinions or votes on v2-0001 vs v3-0001?

David
From 5cf7d9a6c210732c2d5e42f27959dfed8db973c7 Mon Sep 17 00:00:00 2001
From: David Rowley <[email protected]>
Date: Thu, 6 Nov 2025 20:00:39 +1300
Subject: [PATCH v3] Get rid of long datatype in CATCACHE_STATS enabled builds

long is 32-bits on Windows 64 bit.  Switch to a datatype that's 64-bits
on all platforms.  While we're there, use an unsigned type as these
fields count things that have occurred, of which it's not possible to
have negative numbers of.
---
 src/backend/utils/cache/catcache.c | 20 ++++++++++----------
 src/include/utils/catcache.h       | 14 +++++++-------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/backend/utils/cache/catcache.c 
b/src/backend/utils/cache/catcache.c
index 30ac1bd91be..f28ec4feb39 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -461,14 +461,14 @@ static void
 CatCachePrintStats(int code, Datum arg)
 {
        slist_iter      iter;
-       long            cc_searches = 0;
-       long            cc_hits = 0;
-       long            cc_neg_hits = 0;
-       long            cc_newloads = 0;
-       long            cc_invals = 0;
-       long            cc_nlists = 0;
-       long            cc_lsearches = 0;
-       long            cc_lhits = 0;
+       unsigned long long cc_searches = 0;
+       unsigned long long cc_hits = 0;
+       unsigned long long cc_neg_hits = 0;
+       unsigned long long cc_newloads = 0;
+       unsigned long long cc_invals = 0;
+       unsigned long long cc_nlists = 0;
+       unsigned long long cc_lsearches = 0;
+       unsigned long long cc_lhits = 0;
 
        slist_foreach(iter, &CacheHdr->ch_caches)
        {
@@ -476,7 +476,7 @@ CatCachePrintStats(int code, Datum arg)
 
                if (cache->cc_ntup == 0 && cache->cc_searches == 0)
                        continue;                       /* don't print unused 
caches */
-               elog(DEBUG2, "catcache %s/%u: %d tup, %ld srch, %ld+%ld=%ld 
hits, %ld+%ld=%ld loads, %ld invals, %d lists, %ld lsrch, %ld lhits",
+               elog(DEBUG2, "catcache %s/%u: %d tup, %llu srch, %llu+%llu=%llu 
hits, %llu+%llu=%llu loads, %llu invals, %d lists, %llu lsrch, %llu lhits",
                         cache->cc_relname,
                         cache->cc_indexoid,
                         cache->cc_ntup,
@@ -500,7 +500,7 @@ CatCachePrintStats(int code, Datum arg)
                cc_lsearches += cache->cc_lsearches;
                cc_lhits += cache->cc_lhits;
        }
-       elog(DEBUG2, "catcache totals: %d tup, %ld srch, %ld+%ld=%ld hits, 
%ld+%ld=%ld loads, %ld invals, %ld lists, %ld lsrch, %ld lhits",
+       elog(DEBUG2, "catcache totals: %d tup, %llu srch, %llu+%llu=%llu hits, 
%llu+%llu=%llu loads, %llu invals, %llu lists, %llu lsrch, %llu lhits",
                 CacheHdr->ch_ntup,
                 cc_searches,
                 cc_hits,
diff --git a/src/include/utils/catcache.h b/src/include/utils/catcache.h
index 00808e23f49..1419b9d3a1d 100644
--- a/src/include/utils/catcache.h
+++ b/src/include/utils/catcache.h
@@ -69,18 +69,18 @@ typedef struct catcache
         * doesn't break ABI for other modules
         */
 #ifdef CATCACHE_STATS
-       long            cc_searches;    /* total # searches against this cache 
*/
-       long            cc_hits;                /* # of matches against 
existing entry */
-       long            cc_neg_hits;    /* # of matches against negative entry 
*/
-       long            cc_newloads;    /* # of successful loads of new entry */
+       unsigned long long cc_searches; /* total # searches against this cache 
*/
+       unsigned long long cc_hits; /* # of matches against existing entry */
+       unsigned long long cc_neg_hits; /* # of matches against negative entry 
*/
+       unsigned long long cc_newloads; /* # of successful loads of new entry */
 
        /*
         * cc_searches - (cc_hits + cc_neg_hits + cc_newloads) is number of 
failed
         * searches, each of which will result in loading a negative entry
         */
-       long            cc_invals;              /* # of entries invalidated 
from cache */
-       long            cc_lsearches;   /* total # list-searches */
-       long            cc_lhits;               /* # of matches against 
existing lists */
+       unsigned long long cc_invals;   /* # of entries invalidated from cache 
*/
+       unsigned long long cc_lsearches;        /* total # list-searches */
+       unsigned long long cc_lhits;    /* # of matches against existing lists 
*/
 #endif
 } CatCache;
 
-- 
2.43.0

Attachment: v2-0001-Get-rid-of-long-datatype-in-CATCACHE_STATS-enable.patch
Description: Binary data

Attachment: v2-0002-Adjust-MemSet-macro-to-use-size_t-rather-than-lon.patch
Description: Binary data

Reply via email to