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 1uchyf-00G1ZO-6M for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Jul 2025 10:06:05 +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 1uchyd-00AKBx-8U for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Jul 2025 10:06:03 +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 1uchyc-00AKAy-2Z for pgsql-hackers@lists.postgresql.org; Fri, 18 Jul 2025 10:06:03 +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 1uchyZ-008Pxe-2p for pgsql-hackers@postgresql.org; Fri, 18 Jul 2025 10:06:02 +0000 Received: from localhost (unknown [IPv6:2404:7a80:9f01:f500:1788:74de:dc85:ea72]) by mail.clear-code.com (Postfix) with ESMTPSA id 184DD6304EF; Fri, 18 Jul 2025 19:05:54 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com 184DD6304EF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1752833154; bh=NeA9qy8phm/a/2F4Ueu92xvx2dJt1Gdz13YO2nsYUdA=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=Mt4vj0f1bjgbqyz0vvrz5xl62X6Z1VdczTk6CcGmubxll0Srsp7tqUU/gBgkzG2uo pbJ6dBDdzTH9ZrXRO0cLSCnMILwzXFgdhxin/xGCWa1txrsaMzmMEb1wsMdqDgbKU2 sbsNAxk1mdIuOx0soW8U57Zk4S2ikhtqC95ZbJPE= Date: Fri, 18 Jul 2025 19:05:53 +0900 (JST) Message-Id: <20250718.190553.1172585000083080334.kou@clear-code.com> To: sawada.mshk@gmail.com Cc: michael@paquier.xyz, david.g.johnston@gmail.com, tgl@sss.pgh.pa.us, 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: <20250714.173803.865595983884510428.kou@clear-code.com> <20250715.165413.1502624024677287358.kou@clear-code.com> X-Mailer: Mew version 6.8 on Emacs 30.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 184DD6304EF 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]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; TAGGED_RCPT(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; FREEMAIL_CC(0.00)[paquier.xyz,gmail.com,sss.pgh.pa.us,postgresql.org]; FROM_HAS_DN(0.00)[]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_FIVE(0.00)[6] 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 Thu, 17 Jul 2025 13:44:11 -0700, Masahiko Sawada wrote: >> > How about adding accessors instead of splitting >> > Copy{From,To}State to Copy{From,To}ExecutionData? If we use >> > the accessors approach, we can export only needed >> > information step by step without breaking ABI. > > Yeah, while it can export required fields without breaking ABI, I'm > concerned that setter and getter functions could be bloated if we need > to have them for many fields. In general, I choose this approach in my projects even when I need to define many accessors. Because I can hide implementation details from users. I can change implementation details without breaking API/ABI. But PostgreSQL isn't my project. Is there any guideline for PostgreSQL API(/ABI?) design that we can refer for this case? FYI: We need to export at least the following fields: https://www.postgresql.org/message-id/flat/20250714.173803.865595983884510428.kou%40clear-code.com#78fdbccf89742f856aa2cf95eaf42032 > FROM: > > - attnumlist (*) > - bytes_processed > - cur_attname > - escontext > - in_functions (*) > - input_buf > - input_reached_eof > - line_buf > - opts (*) > - raw_buf > - raw_buf_index > - raw_buf_len > - rel (*) > - typioparams (*) > > TO: > > - attnumlist (*) > - fe_msgbuf > - opts (*) Here are pros/cons of the Copy{From,To}ExecutionData approach, right? Pros: 1. We can hide internal data from extensions Cons: 1. Built-in format routines need to refer fields via Copy{From,To}ExecutionData. * This MAY has performance impact. If there is no performance impact, this is not a cons. 2. API/ABI compatibility will be broken when we change exported fields. * I'm not sure whether this is a cons in the PostgreSQL design. Here are pros/cons of the accessors approach: Pros: 1. We can hide internal data from extensions 2. We can export new fields change field names without breaking API/ABI compatibility 3. We don't need to change built-in format routines. So we can assume that there is no performance impact. Cons: 1. We may need to define many accessors * I'm not sure whether this is a cons in the PostgreSQL design. >> Another idea: We'll add Copy{From,To}State::opaque >> eventually. (For example, the v40-0003 patch includes it.) >> >> How about using it to hide fields only for built-in formats? > > What is the difference between your idea and splitting CopyToState > into CopyToState and CopyToExecutionData? 1. We don't need to manage 2 similar data for built-in formats and extensions. * Build-in formats use CopyToExecutionData and extensions use opaque. 2. We can introduce registration API now. * We can work on this topic AFTER we introduce registration API. * e.g.: Add registration API -> Add opaque -> Use opaque for internal fields (we will benchmark this implementation at this time) Thanks, -- kou