Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWLdB-00012w-6g for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Feb 2023 18:20:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pWLd9-0006Mf-MC for pgsql-hackers@arkaria.postgresql.org; Sun, 26 Feb 2023 18:20:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWLd9-0006MV-Ck for pgsql-hackers@lists.postgresql.org; Sun, 26 Feb 2023 18:20:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWLd3-0006da-Dj for pgsql-hackers@postgresql.org; Sun, 26 Feb 2023 18:20:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 31QIK0iY020521; Sun, 26 Feb 2023 13:20:00 -0500 From: Tom Lane To: Andres Freund cc: Kyotaro Horiguchi , melanieplageman@gmail.com, vignesh21@gmail.com, pryzby@telsasoft.com, lukas@fittl.com, alvherre@alvh.no-ip.org, magnus@hagander.net, pgsql-hackers@postgresql.org, thomas.munro@gmail.com, m.sakrejda@gmail.com Subject: Re: pg_stat_bgwriter.buffers_backend is pretty meaningless (and more?) In-reply-to: <20230209050319.chyyup4vtq4jzobq@awork3.anarazel.de> References: <20230124.172203.448918351330829200.horikyota.ntt@gmail.com> <20230124223512.xqp7tjgqvzqokaxq@awork3.anarazel.de> <20230125.165617.724951472557617342.horikyota.ntt@gmail.com> <20230208063814.boyh5ibydbfuo2uk@awork3.anarazel.de> <20230209050319.chyyup4vtq4jzobq@awork3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Wed, 08 Feb 2023 21:03:19 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20519.1677435600.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 26 Feb 2023 13:20:00 -0500 Message-ID: <20520.1677435600@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > Pushed the first (and biggest) commit. More tomorrow. I hadn't run my buildfarm-compile-warning scraper for a little while, but I just did, and I find that this commit is causing warnings on no fewer than 14 buildfarm animals. They all look like ayu | 2023-02-25 23:02:08 | pgstat_io.c:40:14: warning: compari= son of constant 2 with expression of type 'IOObject' (aka 'enum IOObject')= is always true [-Wtautological-constant-out-of-range-compare] ayu | 2023-02-25 23:02:08 | pgstat_io.c:43:16: warning: compari= son of constant 4 with expression of type 'IOContext' (aka 'enum IOContext= ') is always true [-Wtautological-constant-out-of-range-compare] ayu | 2023-02-25 23:02:08 | pgstat_io.c:70:19: warning: compari= son of constant 2 with expression of type 'IOObject' (aka 'enum IOObject')= is always true [-Wtautological-constant-out-of-range-compare] ayu | 2023-02-25 23:02:08 | pgstat_io.c:71:20: warning: compari= son of constant 4 with expression of type 'IOContext' (aka 'enum IOContext= ') is always true [-Wtautological-constant-out-of-range-compare] ayu | 2023-02-25 23:02:08 | pgstat_io.c:115:14: warning: compar= ison of constant 2 with expression of type 'IOObject' (aka 'enum IOObject'= ) is always true [-Wtautological-constant-out-of-range-compare] ayu | 2023-02-25 23:02:08 | pgstat_io.c:118:16: warning: compar= ison of constant 4 with expression of type 'IOContext' (aka 'enum IOContex= t') is always true [-Wtautological-constant-out-of-range-compare] ayu | 2023-02-25 23:02:08 | pgstatfuncs.c:1329:12: warning: com= parison of constant 2 with expression of type 'IOObject' (aka 'enum IOObje= ct') is always true [-Wtautological-constant-out-of-range-compare] ayu | 2023-02-25 23:02:08 | pgstatfuncs.c:1334:17: warning: com= parison of constant 4 with expression of type 'IOContext' (aka 'enum IOCon= text') is always true [-Wtautological-constant-out-of-range-compare] That is, these compilers think that comparisons like io_object < IOOBJECT_NUM_TYPES io_context < IOCONTEXT_NUM_TYPES are constant-true. This seems not good; if they were to actually act on this observation, by removing those loop-ending tests, we'd have a problem. The issue seems to be that code like this: typedef enum IOContext { IOCONTEXT_BULKREAD, IOCONTEXT_BULKWRITE, IOCONTEXT_NORMAL, IOCONTEXT_VACUUM, } IOContext; #define IOCONTEXT_FIRST IOCONTEXT_BULKREAD #define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1) is far too cute for its own good. I'm not sure about how to fix it either. I thought of defining #define IOCONTEXT_LAST IOCONTEXT_VACUUM and make the loop conditions like "io_context <=3D IOCONTEXT_LAST", but that doesn't actually fix the problem. (Even aside from that, I do not find this coding even a little bit mistake-proof: you still have to remember to update the #define when adding another enum value.) We have similar code involving enum ForkNumber but it looks to me like the loop variables are always declared as plain "int". That might be the path of least resistance here. regards, tom lane