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 1rB2QU-009Dml-Ol for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Dec 2023 00:39:39 +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 1rB2QS-00Dd4U-Qo for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Dec 2023 00:39:36 +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 1rB2QQ-00Dd2W-O5 for pgsql-hackers@lists.postgresql.org; Thu, 07 Dec 2023 00:39:36 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rB2QI-009A9y-Ph for pgsql-hackers@postgresql.org; Thu, 07 Dec 2023 00:39:32 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id AD1DA3200A55; Wed, 6 Dec 2023 19:39:23 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 06 Dec 2023 19:39:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1701909563; x=1701995963; bh=QO xzXihmRxpRTdWfbju5tYqvy7LpPvhKmnBL9ZJSRkE=; b=3FAgweQNJBfK1JZEfF W5EIPC4c0wWGEW098KeGIop+WHjVkC7qdVO9mdbB7He/I2p/HsznGKk5mDIjGFGa khKHvRDWz+r96vZuqNVqT3PAA7VK+4VvXqjJ11mrYDzuij3+gbNGrW0rwD5OGCzQ /IS8OPFMI+XEtNyV4kXSl/Z+Dcqrj+jY4cRTikTJiT0OX35/nskwdYPjuDSmFeVv 1+YZBikGtSZvKNEP696TUk52FXweN8zhPAxJoGzZd9W6z9gUvF0GYj+bdkUS5UGz ILBNp16PgBWTRqMf3jrP4IGnU+BexU/BFKFT5gqj+N4Xq5LPhWBYsF1i4lq6g9MH gIKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1701909563; x=1701995963; bh=QOxzXihmRxpRT dWfbju5tYqvy7LpPvhKmnBL9ZJSRkE=; b=hDueMDdcRKcaklUw5zueCUqKCB9yV qIDicaZnMzFVJWJx4f70aPAazwbo/qm1SjhwatFR4qizCicyrB84zYAJ7cblepLT rcgWpqzHx083TMByEAbvP7asdbBftNtr+UVbyoyDT3I1IAQ5YfOKAco0BggwVwva 1f3QLmz+bJrrzenLTz48nChDguTccncjAKOSoxHdoM7tr2Ulo/HD+7vU4xuziOzp c6t1O1ISB5fN/n3EuHqSmzOHWR90rygDfCJRek2W2785App6j2PCwYlw0D9ZGVwy pFsvOgCz2ciS3EKPtMowgg6RjVftp0LYqZBZ41JM2kgIM5vU/kGpOeqHw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudekuddgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfeehmdenucfjughrpeffhf fvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepgeffjeevgfevuddvjedtvddtieejheduueelvddufedtgfefjedvkeevkeeivddv necuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghr rdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Dec 2023 19:39:20 -0500 (EST) Date: Thu, 7 Dec 2023 09:38:59 +0900 From: Michael Paquier To: Junwang Zhao Cc: Sutou Kouhei , nathandbossart@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations Message-ID: References: <20231206.151908.897707799247386849.kou@clear-code.com> <20231206.162834.1390394858102165899.kou@clear-code.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="cvQUBATM3B8Y3T9j" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --cvQUBATM3B8Y3T9j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 06, 2023 at 10:07:51PM +0800, Junwang Zhao wrote: > I read the thread[1] you posted and I think Andres's suggestion sounds gr= eat. >=20 > Should we extract both *copy to* and *copy from* for the first step, in t= hat > case we can add the pg_copy_handler catalog smoothly later. >=20 > Attached V4 adds 'extract copy from' and it passed the cirrus ci, > please take a look. >=20 > I added a hook *copy_from_end* but this might be removed later if not use= d. >=20 > [1]: https://www.postgresql.org/message-id/20180211211235.5x3jywe5z3lkgcs= r%40alap3.anarazel.de I was looking at the differences between v3 posted by Sutou-san and v4 from you, seeing that: +/* Routines for a COPY HANDLER implementation. */ +typedef struct CopyHandlerOps { /* Called when COPY TO is started. This will send a header. */ - void (*start) (CopyToState cstate, TupleDesc tupDesc); + void (*copy_to_start) (CopyToState cstate, TupleDesc tupDesc); =20 /* Copy one row for COPY TO. */ - void (*one_row) (CopyToState cstate, TupleTableSlot *slot); + void (*copy_to_one_row) (CopyToState cstate, TupleTableSlot *sl= ot); =20 /* Called when COPY TO is ended. This will send a trailer. */ - void (*end) (CopyToState cstate); -} CopyToFormatOps; + void (*copy_to_end) (CopyToState cstate); + + void (*copy_from_start) (CopyFromState cstate, TupleDesc tupDes= c); + bool (*copy_from_next) (CopyFromState cstate, ExprContext *econ= text, + Datum *values, bool *nulls); + void (*copy_from_error_callback) (CopyFromState cstate); + void (*copy_from_end) (CopyFromState cstate); +} CopyHandlerOps; And we've spent a good deal of time refactoring the copy code so as the logic behind TO and FROM is split. Having a set of routines that groups both does not look like a step in the right direction to me, and v4 is an attempt at solving two problems, while v3 aims to improve one case. It seems to me that each callback portion should be focused on staying in its own area of the code, aka copyfrom*.c or copyto*.c. -- Michael --cvQUBATM3B8Y3T9j Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmVxFCMACgkQnvQgOdby QH1tKA/+NGCDhrVdDossqqDxpQBFevQCaF68W+PnAyeLS8aivVQjibw4iv6I4kJS Tt+YP0VmUY9rSJ8AEz7fMPikogv49qui1v74vjaezwkkyiwwOKseFgeL2kMZ9hQz Gsozv72Dp+LlLM4DBGAH+RHEa4TYYjUDzHYjBsfMKCFlfIhgc0/KUYFGB4MwpPB+ r2TOzpCWKDVnAyzacXQEdm60CPJ8CAwRG8+iiu/ZvXgAp2B4S1+qoo/k7ahnb5qa c7zTCgooEKycaWG7nPXEeguGBtXZ3J7omGILdd/1qXI13xHg9zK0SY7kEObryldF iXxlaeIVpVXNFwpohV5JkXJgqQQUnv1zk4oNmjZS9LBcjpxuta6iBhUTK6pJYEIs 2JstC9TLW6Qz2Aozm2SnVbRuOPVcwnh5tp8fRPkxFpDXPmCRfujzsNCesh8RcUQP 51XnAIGkIeLshu1mknsNKqw/nNY01y03xV8cAbbxabEkkAnhcMzdjNKYDKACF594 JY9iP08RhIQ5Z1QtyShUTwWCz2/i/0tF8o1cxur24fxUiDzm1p7Zbj9PgMUjvbCI VS1ZKGRkyp5WeL2t6YIEmmeMAkzLDodiCouQR/46gvmo0YQUk3IyqyafvHq8pxMe ir3t+Ee8Zq9cyPXbRuz88gpkMuKICsw19XHQzDblKHXv0wlzS1w= =T7+F -----END PGP SIGNATURE----- --cvQUBATM3B8Y3T9j--