Re: pgbench - use pg logging capabilities

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Michael Paquier <michael(at)paquier(dot)xyz>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgbench - use pg logging capabilities
Date: 2020-01-10 01:09:29
Message-ID: 19312.1578618569@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> On 2020-Jan-09, Fabien COELHO wrote:
>> - if (unlikely(__pg_log_level <= PG_LOG_DEBUG))
>> + if (pg_log_debug_level)
>> {

> Umm ... I find the original exceedingly ugly, but the new line is
> totally impenetrable.

So, I had not been paying any attention to this thread, but that
snippet is already enough to set off alarm bells.

1. (problem with already-committed code, evidently) The C standard is
quite clear that

-- All identifiers that begin with an underscore and
either an uppercase letter or another underscore are
always reserved for any use.

-- All identifiers that begin with an underscore are
always reserved for use as identifiers with file scope
in both the ordinary and tag name spaces.

"Reserved" in this context appears to mean "reserved for use by
system headers and/or compiler special behaviors".

Declaring our own global variables with double-underscore prefixes is not
just asking for trouble, it's waving a red flag in front of a bull.

2. (problem with proposed patch) I share Alvaro's allergy for replacing
uses of a common variable with a bunch of macros, especially macros that
don't look like macros. That's not reducing the reader's cognitive
burden. I'd even say it's actively misleading the reader, because what
the new code *looks* like it's doing is referencing several independent
global variables. We don't need our code to qualify as an entry for
the Obfuscated C Contest.

The notational confusion could be solved perhaps by writing the macros
with function-like parentheses, but it still doesn't seem like an
improvement. In particular, the whole point here is to have a common
idiom for logging, but I'm unconvinced that every frontend program
should be using unlikely() in this particular way. Maybe it's unlikely
for pgbench's usage that verbose logging would be turned on, but why
should we build in an assumption that that's universally the case?

TBH, my recommendation would be to drop *all* of these likely()
and unlikely() calls. What evidence have you got that those are
meaningfully improving the quality of the generated code? And if
they're buried inside macros, they certainly aren't doing anything
useful in terms of documenting the code.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Deng, Gang 2020-01-10 01:18:39 RE: [PATCH] Resolve Parallel Hash Join Performance Issue
Previous Message Deng, Gang 2020-01-10 00:52:42 RE: [PATCH] Resolve Parallel Hash Join Performance Issue