Re: Some efforts to get rid of "long" in our codebase

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Some efforts to get rid of "long" in our codebase
Date: 2025-11-10 00:53:36
Message-ID: CAApHDvqVzLzb02Uuaz2uBjs1cfSGLUDpibTTCsKHyeKNFUt3uA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 7 Nov 2025 at 07:26, Peter Eisentraut <peter(at)eisentraut(dot)org> 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

Attachment Content-Type Size
v3-0001-Get-rid-of-long-datatype-in-CATCACHE_STATS-enable.patch.txt text/plain 3.8 KB
v2-0001-Get-rid-of-long-datatype-in-CATCACHE_STATS-enable.patch application/octet-stream 3.8 KB
v2-0002-Adjust-MemSet-macro-to-use-size_t-rather-than-lon.patch application/octet-stream 4.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-11-10 00:57:14 Re: Extend injection_points_attach() to accept a user-defined function
Previous Message jian he 2025-11-10 00:53:02 Re: Emitting JSON to file using COPY TO