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 1tomAA-00FCwS-2X for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Mar 2025 16:27:34 +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 1tomAA-004oyk-CY for pgsql-hackers@arkaria.postgresql.org; Sun, 02 Mar 2025 16:27:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tomAA-004oyc-2i for pgsql-hackers@lists.postgresql.org; Sun, 02 Mar 2025 16:27:32 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tomA4-000YKv-38 for pgsql-hackers@postgresql.org; Sun, 02 Mar 2025 16:27:32 +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 522GRKAU3191031; Sun, 2 Mar 2025 11:27:20 -0500 From: Tom Lane To: Junwang Zhao cc: Sutou Kouhei , sawada.mshk@gmail.com, michael@paquier.xyz, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations In-reply-to: References: <20250301.065821.2101946731315576357.kou@clear-code.com> <20250301.071737.71492652427941293.kou@clear-code.com> <20250301.115009.424844407736647598.kou@clear-code.com> Comments: In-reply-to Junwang Zhao message dated "Sun, 02 Mar 2025 15:40:11 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3191029.1740932840.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 02 Mar 2025 11:27:20 -0500 Message-ID: <3191030.1740932840@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Junwang Zhao writes: > While review another thread (Emitting JSON to file using COPY TO), > I found the recently committed patches on this thread pass the > CopyFormatOptions struct directly rather a pointer of the struct > as a function parameter of CopyToGetRoutine and CopyFromGetRoutine. Coverity is unhappy about that too: /srv/coverity/git/pgsql-git/postgresql/src/backend/commands/copyto.c: 177 = in CopyToGetRoutine() 171 .CopyToOneRow =3D CopyToBinaryOneRow, 172 .CopyToEnd =3D CopyToBinaryEnd, 173 }; 174 = 175 /* Return a COPY TO routine for the given options */ 176 static const CopyToRoutine * >>> CID 1643911: Performance inefficiencies (PASS_BY_VALUE) >>> Passing parameter opts of type "CopyFormatOptions" (size 184 bytes= ) by value, which exceeds the low threshold of 128 bytes. 177 CopyToGetRoutine(CopyFormatOptions opts) 178 { 179 if (opts.csv_mode) 180 return &CopyToRoutineCSV; (and likewise for CopyFromGetRoutine). I realize that these functions aren't called often enough for performance to be an overriding concern, but it still seems like poor style. > Then I took a quick look at the newly rebased patch set and > found Sutou has already fixed this issue. +1, except I'd suggest declaring the parameters as "const CopyFormatOptions *opts". regards, tom lane