Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEuuY-004qNA-CE for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Jun 2024 17:58:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sEuuY-00ANP9-Bk for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Jun 2024 17:58:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEuuY-00ANP1-21 for pgsql-hackers@lists.postgresql.org; Wed, 05 Jun 2024 17:58:58 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sEuuV-003c8c-Hw for pgsql-hackers@postgresql.org; Wed, 05 Jun 2024 17:58:56 +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 455HwsxD892532; Wed, 5 Jun 2024 13:58:54 -0400 From: Tom Lane To: Nathan Bossart cc: Neil Conway , pgsql-hackers@postgresql.org Subject: Re: small pg_dump code cleanup In-reply-to: References: Comments: In-reply-to Nathan Bossart message dated "Wed, 05 Jun 2024 11:37:54 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <892530.1717610334.1@sss.pgh.pa.us> Date: Wed, 05 Jun 2024 13:58:54 -0400 Message-ID: <892531.1717610334@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathan Bossart writes: > On Wed, Jun 05, 2024 at 12:22:03PM -0400, Neil Conway wrote: >> (1) Names like `getXXX` for these functions suggest to me that they return >> a value, rather than side-effecting. I realize some variants continue to >> return a value, but the majority no longer do. Perhaps a name like >> lookupXXX() or readXXX() would be clearer? > What about collectXXX() to match similar functions in pg_dump.c (e.g., > collectRoleNames(), collectComments(), collectSecLabels())? Personally I see nothing much wrong with leaving them as getXXX. >> (2) These functions malloc() a single ntups * sizeof(struct) allocation and >> then index into it to fill-in each struct before entering it into the hash >> table. It might be more straightforward to just malloc each individual >> struct. > That'd increase the number of allocations quite significantly, but I'd be > surprised if that was noticeable outside of extreme scenarios. At the > moment, I'm inclined to leave these as-is for this reason and because I > doubt it'd result in much cleanup, but I'll yield to the majority opinion > here. I think that would be quite an invasive change; it would require many hundreds of edits like - finfo[i].dobj.objType = DO_FUNC; + finfo->dobj.objType = DO_FUNC; which aside from being tedious would create a back-patching hazard. So I'm kind of -0.1 or so. Another angle to this is that Coverity and possibly other tools tend to report that these functions leak these allocations, apparently because they don't notice that pointers into the allocations get stored in hash tables by a subroutine. I'm not sure if making this change would make that worse or better. If we really want to change it, that might be worth checking somehow before we jump. regards, tom lane