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 1ra7WC-0089N5-7Y for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 05:09:12 +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 1ra7WA-0040DQ-Tx for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 05:09:10 +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 1ra7W9-0040DI-QU for pgsql-hackers@lists.postgresql.org; Wed, 14 Feb 2024 05:09:10 +0000 Received: from mail.clear-code.com ([2401:2500:102:3039:153:126:206:245]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ra7W4-006eig-Rv for pgsql-hackers@postgresql.org; Wed, 14 Feb 2024 05:09:07 +0000 Received: from localhost (unknown [IPv6:2404:7a80:89c1:1200:6af9:2266:1443:f149]) by mail.clear-code.com (Postfix) with ESMTPSA id 5ECEF61791D; Wed, 14 Feb 2024 14:08:54 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com 5ECEF61791D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1707887334; bh=r/1YklYkavURfYtSyyRCE5+YM/kS3MeBB2RVRjJpMd0=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=RlLioO+VsaCp6DauNPUo/XWQInXhnvlcGpkl+LAhnO5YCEDJ2MKIRozDYRPbsEx/B dsd+N0bhzyGXO2z/dj3rO83oj1d6rjjBPksl6EdjyUXw5HkLgH4Pgi/ZbrzuKHPwIG qOYC2wba2XeSqenad+14bqrxUIphVDGvEGAM3tUg= Date: Wed, 14 Feb 2024 14:08:51 +0900 (JST) Message-Id: <20240214.140851.211967754365096862.kou@clear-code.com> To: michael@paquier.xyz Cc: andres@anarazel.de, sawada.mshk@gmail.com, zhjwpku@gmail.com, andrew@dunslane.net, nathandbossart@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations From: Sutou Kouhei In-Reply-To: References: <20240209192705.5qdilvviq3py2voq@awork3.anarazel.de> <20240213.173340.1518143507526518973.kou@clear-code.com> X-Mailer: Mew version 6.8 on Emacs 29.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 5ECEF61791D 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]; ARC_NA(0.00)[]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; TAGGED_RCPT(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_COUNT_ZERO(0.00)[0]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; URIBL_BLOCKED(0.00)[localhost:helo,paquier.xyz:email]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_CC(0.00)[anarazel.de,gmail.com,dunslane.net,postgresql.org]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_DN_NONE(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; SURBL_MULTI_FAIL(0.00)[paquier.xyz:server fail,localhost:server fail] 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 Wed, 14 Feb 2024 12:28:38 +0900, Michael Paquier wrote: >> How about the attached patch approach? If it's a desired >> approach, I can also write a separated patch for COPY TO. > > Hmm, I have not studied that much, but my first impression was that we > would not require any new facility in fmgr.c, but perhaps you're right > and it's more elegant to pass a InitFunctionCallInfoData this way. I'm not familiar with the fmgr.c related code base but it seems that we abstract {,binary-}input function call by fmgr.c. So I think that it's better that we follow the design. (If there is a person who knows the fmgr.c related code base, please help us.) > PrepareInputFunctionCallInfo() looks OK as a name, but I'm less a fan > of PreparedInputFunctionCallSafe() and its "Prepared" part. How about > something like ExecuteInputFunctionCallSafe()? I understand the feeling. SQL uses "prepared" for "prepared statement". There are similar function names such as InputFunctionCall()/InputFunctionCallSafe()/DirectInputFunctionCallSafe(). They execute (call) an input function but they use "call" not "execute" for it... So "Execute...Call..." may be redundant... How about InputFunctionCallSafeWithInfo(), InputFunctionCallSafeInfo() or InputFunctionCallInfoCallSafe()? > I may be able to look more at that next week, and I would surely check > the impact of that with a simple COPY query throttled by CPU (more > rows and more attributes the better). Thanks! > Note that I've reverted 06bd311bce24 for > the moment, as this is just getting in the way of the main patch, and > that was non-optimal once there is a per-row callback. Thanks for sharing the information. I'll rebase on master when I create the v15 patch. >> diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c >> index 41f6bc43e4..a43c853e99 100644 >> --- a/src/backend/commands/copyfrom.c >> +++ b/src/backend/commands/copyfrom.c >> @@ -1691,6 +1691,10 @@ BeginCopyFrom(ParseState *pstate, >> /* We keep those variables in cstate. */ >> cstate->in_functions = in_functions; >> cstate->typioparams = typioparams; >> + if (cstate->opts.binary) >> + cstate->fcinfo = PrepareInputFunctionCallInfo(); >> + else >> + cstate->fcinfo = PrepareReceiveFunctionCallInfo(); > > Perhaps we'd better avoid more callbacks like that, for now. I'll not use a callback for this. I'll not change this part after we introduce Copy{To,From}Routine. cstate->fcinfo isn't used some custom COPY format handlers such as Apache Arrow handler like cstate->in_functions and cstate->typioparams. But they will be always allocated. It's a bit wasteful for those handlers but we may not care about it. So we can always use "if (state->opts.binary)" condition here. BTW... This part was wrong... Sorry... It should be: if (cstate->opts.binary) cstate->fcinfo = PrepareReceiveFunctionCallInfo(); else cstate->fcinfo = PrepareInputFunctionCallInfo(); Thanks, -- kou