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 1oxtwh-0003H7-F5 for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Nov 2022 17:54:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oxtvh-0000rX-W7 for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Nov 2022 17:53:01 +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 1oxtvh-0000rO-N7 for pgsql-hackers@lists.postgresql.org; Wed, 23 Nov 2022 17:53:01 +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 1oxtvf-0000qE-CP for pgsql-hackers@postgresql.org; Wed, 23 Nov 2022 17:53:01 +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 2ANHqvEb3722578; Wed, 23 Nov 2022 12:52:57 -0500 From: Tom Lane To: Justin Pryzby cc: pgsql-hackers@postgresql.org Subject: Re: code cleanups In-reply-to: <20221123172436.GJ11463@telsasoft.com> References: <20221123172436.GJ11463@telsasoft.com> Comments: In-reply-to Justin Pryzby message dated "Wed, 23 Nov 2022 11:24:36 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3722576.1669225977.1@sss.pgh.pa.us> Date: Wed, 23 Nov 2022 12:52:57 -0500 Message-ID: <3722577.1669225977@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Justin Pryzby writes: > Some modest cleanups I've accumulated. Hmm ... I don't especially care for either 0001 or 0002, mainly because I do not agree that this is good style: - bool nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS]; + bool nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS] = {0}; It causes the code to be far more in bed than I like with the assumption that we're initializing to physical zeroes. The explicit loop method can be trivially adjusted to initialize to "true" or some other value; at least for bool arrays, that's true of memset'ing as well. But this, if you decide you need something other than zeroes, is a foot-gun. In particular, someone whose C is a bit weak might mistakenly think that bool nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS] = {true}; will set all the array elements to true. Nor is there a plausible argument that this is more efficient. So I don't care for this approach and I don't want to adopt it. 0003: I agree with getting rid of the duplicated code, but did you go far enough? Isn't the code just above those parent checks also pretty redundant? It would be more intellectually consistent to move the full responsibility for setting acl_ok into a subroutine. This shows in the patch as you have it because the header comment for recheck_parent_acl is completely out-of-context. 0004: Right, somebody injected code in a poorly chosen place (yet another victim of the "add at the end" anti-pattern). 0005: No particular objection, but it's not much of an improvement either. It seems maybe a shade less consistent with the following line. 0006: These changes will cause fetching of one more source byte than was fetched before. I'm not sure that's safe, so I don't think this is an improvement. regards, tom lane