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 1tn4in-001lm2-KU for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Feb 2025 23:52:18 +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 1tn4im-00AzFn-8y for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Feb 2025 23:52:16 +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 1tn4il-00AzEw-5G for pgsql-hackers@lists.postgresql.org; Tue, 25 Feb 2025 23:52:15 +0000 Received: from mail.clear-code.com ([153.126.203.179]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tn4if-00069z-1r for pgsql-hackers@postgresql.org; Tue, 25 Feb 2025 23:52:13 +0000 Received: from localhost (unknown [IPv6:2404:7a80:9f01:f500:acd0:2aa3:7b08:7206]) by mail.clear-code.com (Postfix) with ESMTPSA id CA12A684B7B; Wed, 26 Feb 2025 08:52:01 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com CA12A684B7B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1740527522; bh=Fnyn0HYU8gknebTysToZauBuxuT6r7BbXFqFUML1QFo=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=vz3vp5qJRN6OycJtO/WSad7P/p6cXkQGPw3A2AehlZvUUPX1Iyws4MNa/p1jfUHFz jWvHOyMyLDoM0SPF9y9209CnFBN97ibwcWmvq4asa1MykC8dZbs17ZBU3GvyeAlY4r 2RFTk/GhgDLIugroyulK4qSVz0mj7uwcowd9Gw98= Date: Wed, 26 Feb 2025 08:51:59 +0900 (JST) Message-Id: <20250226.085159.1492932557196528740.kou@clear-code.com> To: sawada.mshk@gmail.com Cc: michael@paquier.xyz, zhjwpku@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations From: Sutou Kouhei In-Reply-To: References: <20250221.114812.86438027655536928.kou@clear-code.com> X-Mailer: Mew version 6.8 on Emacs 29.4 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: CA12A684B7B X-Rspamd-Server: mail.clear-code.com X-Spamd-Result: default: False [2.90 / 999.00]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; RCVD_COUNT_ZERO(0.00)[0]; MIME_TRACE(0.00)[0:+]; FREEMAIL_TO(0.00)[gmail.com]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[paquier.xyz,gmail.com,postgresql.org]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_THREE(0.00)[4] X-Rspamd-Action: no action List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, In "Re: Make COPY format extendable: Extract COPY TO format implementations" on Tue, 25 Feb 2025 14:05:28 -0800, Masahiko Sawada wrote: > The first two patches are refactoring patches (+ small performance > improvements). I've reviewed these patches again and attached the > updated patches. I reorganized the function order and updated comments > etc. I find that these patches are reasonably ready to push. Could you > review these versions? I'm going to push them, barring objections and > further comments. Sure. Here are some minor comments: 0001: Commit message: > or CSV mode. The performance benchmark results showed ~5% performance > gain intext or CSV mode. intext -> in text > --- a/src/backend/commands/copyto.c > +++ b/src/backend/commands/copyto.c > @@ -20,6 +20,7 @@ > #include "commands/copy.h" > +#include "commands/copyapi.h" We can remove '#include "commands/copy.h"' because it's included in copyapi.h. (0002 does it.) > @@ -254,6 +502,35 @@ CopySendEndOfRow(CopyToState cstate) > +/* > + * Wrapper function of CopySendEndOfRow for text and CSV formats. Sends the > + * the line termination and do common appropriate things for the end of row. > + */ Sends the the line -> Sends the line > --- /dev/null > +++ b/src/include/commands/copyapi.h > + /* End a COPY TO. This callback is called once at the end of COPY FROM */ The last "." is missing: ... COPY FROM. 0002: Commit message: > This change is a preliminary step towards making the COPY TO command > extensible in terms of output formats. COPY TO -> COPY FROM > --- a/src/backend/commands/copyfromparse.c > +++ b/src/backend/commands/copyfromparse.c > @@ -1087,7 +1132,7 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext, > static bool > -CopyReadLine(CopyFromState cstate) > +CopyReadLine(CopyFromState cstate, bool is_csv) > @@ -1163,7 +1208,7 @@ CopyReadLine(CopyFromState cstate) > static bool > -CopyReadLineText(CopyFromState cstate) > +CopyReadLineText(CopyFromState cstate, bool is_csv) We may want to add a comment why we don't use "inline" nor "pg_attribute_always_inline" here: https://www.postgresql.org/message-id/CAD21AoBNfKDbJnu-zONNpG820ZXYC0fuTSLrJ-UdRqU4qp2wog%40mail.gmail.com > Yes, I'm not sure it's really necessary to make it inline since the > benchmark results don't show much difference. Probably this is because > the function has 'is_csv' in some 'if' branches but the compiler > cannot optimize out the whole 'if' branches as most 'if' branches > check 'is_csv' and other variables. Or we can add "inline" not "pg_attribute_always_inline" here as a hint for compiler. > --- a/src/include/commands/copyapi.h > +++ b/src/include/commands/copyapi.h > @@ -52,4 +52,50 @@ typedef struct CopyToRoutine > + /* End a COPY FROM. This callback is called once at the end of COPY FROM */ The last "." is missing: ... COPY FROM. I think that these patches are ready to push too. Thanks, -- kou