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 1uTxnU-00D1D9-FV for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jun 2025 07:10:25 +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 1uTxnS-009yUo-5q for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Jun 2025 07:10:22 +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 1uTxnR-009yUg-3E for pgsql-hackers@lists.postgresql.org; Tue, 24 Jun 2025 07:10:22 +0000 Received: from mail.clear-code.com ([153.126.203.179]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uTxnO-003gee-0p for pgsql-hackers@postgresql.org; Tue, 24 Jun 2025 07:10:20 +0000 Received: from localhost (unknown [IPv6:2404:7a80:9f01:f500:1788:74de:dc85:ea72]) by mail.clear-code.com (Postfix) with ESMTPSA id 7E25966FFAE; Tue, 24 Jun 2025 16:10:11 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com 7E25966FFAE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1750749011; bh=lxORcV500ZQIPua/xqJgMsqBKsF+Crvek0/fMHsv6RY=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=mU8bcLgXyJP+HEcS/8aPiSn8tsUj8UxRT2GHtOqxvqHclwni9OjRb+2rn2JWOJjCi uINqChDKQ17kXBkHwrdIpFIUDltqaFBx4M/1IVMy53BJ79D5wlExp5Ghhi4nkUxgV6 g8gjN5eAIrqcvl6n6bDrw5eDTugnmu/9pE2JaV/A= Date: Tue, 24 Jun 2025 16:10:09 +0900 (JST) Message-Id: <20250624.161009.195478431761017966.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: <20250624.141150.380751236499958086.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-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,sss.pgh.pa.us,postgresql.org]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_FIVE(0.00)[6] X-Rspamd-Server: mail.clear-code.com X-Rspamd-Action: no action X-Rspamd-Queue-Id: 7E25966FFAE 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, 24 Jun 2025 15:24:23 +0900, Masahiko Sawada wrote: >> It's natural to add more related APIs with this >> approach. The single registration API provides one feature >> by one operation. If we use the RegisterCopyRoutine() for >> FROM and TO formats API, it's not natural that we add more >> related APIs. In this case, some APIs may provide multiple >> features by one operation and other APIs may provide single >> feature by one operation. Developers may be confused with >> the API. For example, developers may think "what does mean >> NULL here?" or "can we use NULL here?" for >> "RegisterCopyRoutine("new-format", NewFormatFromRoutine, >> NULL)". > > We can document it in the comment for the registration function. I think that API that can be understandable without the additional note is better API than API that needs some notes. Why do you suggest the RegisterCopyRoutine("new-format", NewFormatFromRoutine, NewFormatToRoutine) API? You want to remove the duplicated codes in RegisterCopy{From,To}Routine(), right? I think that we can do it by creating a convenient function that has the duplicated codes extracted from RegisterCopy{From,To}Routine() and RegisterExtensionExplainOption(). BTW, what do you think about my answer (one feature by one operation API is more extendable API) for your question (extendability and API compatibility)? > Suppose that extension-A implements only CopyToRoutine for the > custom-format-X with the format name 'myformat' and extension-B > implements only CopyFromRoutine for the custom-format-Y with the same > name, if users load both extension-A and extension-B, it seems to me > that extension-A registers the custom-format-X format as 'myformat' > only with CopyToRoutine, and extension-B overwrites the 'myformat' > registration by adding custom-format-Y's CopyFromRoutine. However, if > users register extension-C that implements both routines with the > format name 'myformat', they can register neither extension-A nor > extension-B, which seems to me that we don't allow overwriting the > registration in this case. Do you assume that users use extension-A, extension-B and extension-C without reading their documentation? If users read their documentation before users use them, users can know all of them use the same format name 'myformat' and which extension provides Copy{From,To}Routine. In this case, these users (who don't read documentation) will be confused with the RegisterCopyRoutine("new-format", NewFormatFromRoutine, NewFormatToRoutine) API too. Do we really need to care about this case? > I think the core issue appears to be the internal management of custom > format entries but the current patch does enable registration > overwriting in the former case (extension-A and extension-B case). This is the same behavior as existing custom EXPLAIN option implementation. Should we use different behavior here? >> >> FYI: RegisterCopy{From,To}Routine() uses the same logic >> >> as RegisterExtensionExplainOption(). >> > >> > I'm concerned that the patch has duplicated logics for the >> > registration of COPY FROM and COPY TO. >> >> We can implement a convenient routine that can be used for >> RegisterExtensionExplainOption() and >> RegisterCopy{From,To}Routine() if it's needed. > > I meant there are duplicated codes in COPY FROM and COPY TO. For > instance, RegisterCopyFromRoutine() and RegisterCopyToRoutine() have > the same logic. Yes, I understand it. I wanted to say that we can remove the duplicated codes by introducing a RegisterSomething() function that can be used by RegisterExtensionExplainOption() and RegisterCopy{From,To}Routine(): void RegisterSomething(...) { /* Common codes in RegisterExtensionExplainOption() and RegisterCopy{From,To}Routine() ... */ } void RegisterExtensionExplainOption(...) { RegisterSomething(...); } void RegisterCopyFromRoutine(...) { RegisterSomething(...); } void RegisterCopyToRoutine(...) { RegisterSomething(...); } You think that this approach can't remove the duplicated codes, right? >> > InitPostgres() is not a correct function as it's a process >> > initialization function. Probably we don't necessarily need to >> > register the built-in formats in the same way as custom formats. A >> > simple solution would be to have separate arrays for built-in formats >> > and custom formats and have the GetCopy[To|From]Routine() search both >> > arrays (built-in array first). >> >> We had a discussion that we should dog-food APIs: >> >> https://www.postgresql.org/message-id/flat/CAKFQuwaCHhrS%2BRE4p_OO6d7WEskd9b86-2cYcvChNkrP%2B7PJ7A%40mail.gmail.com#e6d1cdd04dac53eafe34b784ac47b68b >> >> > We should (and usually do) dog-food APIs when reasonable >> > and this situation seems quite reasonable. >> >> In this case, we don't need to dog-food APIs, right? > > Yes, I think so. OK. I don't have a strong opinion for it. If nobody objects it, I'll do it when I update the patch set. Thanks, -- kou