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 1rVMLP-00GRyE-J6 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 01:58: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 1rVMLO-000Jo1-HA for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 01:58:22 +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 1rVMLM-000Jnt-SD for pgsql-hackers@lists.postgresql.org; Thu, 01 Feb 2024 01:58:22 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rVMLI-004oT1-FK for pgsql-hackers@postgresql.org; Thu, 01 Feb 2024 01:58:20 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id C9E873200AAA; Wed, 31 Jan 2024 20:58:11 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 31 Jan 2024 20:58:12 -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:subject :subject:to:to; s=fm3; t=1706752691; x=1706839091; bh=XXeMR7G1vX m5hx4OEEMgqnVvfKViMWIxSpALzSJGudQ=; b=GfzNWbcMnGuRRrOi3GTvmJE2Mn hErcMxF1DW5laA5/+jiQOgjOwZbg1Y3jlGEAVoUjobgDLSkboYb1iMyD9+WqcKcd p+7CsRDsiaTrFiBLH2bjTBR4GfZVo6gLYnS/NXDEuc3jwQEuip12ec6wuxZYBkd1 Ow9x1KlHlptJvL//UDH0G0qf3DBcNgcjOSA8Jyp82wzLB57bMRiAEwTu20WTMu51 WLIBPZw7py8oRYEIFKAfn7Pq3ZGAXUGjht6ORIZWLBwZnTNWnuFMWcJfFFDQUAW4 ArpWGb8/47+dwMmfXsSM65qUQLHsA8kLtRHPJUQD9rIo8R5YgZO7mJEYBXJA== 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:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1706752691; x=1706839091; bh=XXeMR7G1vXm5hx4OEEMgqnVvfKVi MWIxSpALzSJGudQ=; b=bG4uKwIgvVPSp6cmjYiD0Jjw6VGadunETwgkZadMNIQW Kkv4gwucXMh40lKBkVHSRMH+fF1BL/NlSNSyHx/CmiEcyYcCWjC+GePvbBNuDhc0 YuHqRkHsBCvQ9YeE8HLl8cp6VmFOch4oEiSWq78Ws3FH8dscKSJ7vlnpZRNB0/Bm g0riwnERWy2Cf4oPmVv+doVoBUYeQcUvWp6GuoUpbq7zWkg894dJIqbE6newCBW8 8ToJAHjYpy08KvisCdLe/FkNE/vvKCILHtiggSqPM5SgSnl6GHk8tYW8Fg51CoU/ NWm8zeAYMyP3rdpTCQXjqKGgD/PYr6lFZ6Gvmh5RtA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedutddggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfeehmdenucfjughrpeffhf fvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepjeejtdelleeggeelffduhfejtdeuvdekkeethffhuedvvdeuudeugeefudevtdei necuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 31 Jan 2024 20:58:08 -0500 (EST) Date: Thu, 1 Feb 2024 10:57:58 +0900 From: Michael Paquier To: Sutou Kouhei Cc: 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 Message-ID: References: <20240130.171511.2014195814665030502.kou@clear-code.com> <20240131.141122.279551156957581322.kou@clear-code.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="/Gc+32m0Y099A10m" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --/Gc+32m0Y099A10m Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 31, 2024 at 02:39:54PM +0900, Michael Paquier wrote: > Thanks, I'm looking into that now. I have much to say about the patch, but for now I have begun running some performance tests using the patches, because this thread won't get far until we are sure that the callbacks do not impact performance in some kind of worst-case scenario. First, here is what I used to setup a set of tables used for COPY FROM and COPY TO (requires [1] to feed COPY FROM's data to the void, and note that default values is to have a strict control on the size of the StringInfos used in the copy paths): CREATE EXTENSION blackhole_am; CREATE OR REPLACE FUNCTION create_table_cols(tabname text, num_cols int) RETURNS VOID AS $func$ DECLARE query text; BEGIN query :=3D 'CREATE UNLOGGED TABLE ' || tabname || ' ('; FOR i IN 1..num_cols LOOP query :=3D query || 'a_' || i::text || ' int default 1'; IF i !=3D num_cols THEN query :=3D query || ', '; END IF; END LOOP; query :=3D query || ')'; EXECUTE format(query); END $func$ LANGUAGE plpgsql; -- Tables used for COPY TO SELECT create_table_cols ('to_tab_1', 1); SELECT create_table_cols ('to_tab_10', 10); INSERT INTO to_tab_1 SELECT FROM generate_series(1, 10000000); INSERT INTO to_tab_10 SELECT FROM generate_series(1, 10000000); -- Data for COPY FROM COPY to_tab_1 TO '/tmp/to_tab_1.bin' WITH (format binary); COPY to_tab_10 TO '/tmp/to_tab_10.bin' WITH (format binary); COPY to_tab_1 TO '/tmp/to_tab_1.txt' WITH (format text); COPY to_tab_10 TO '/tmp/to_tab_10.txt' WITH (format text); -- Tables used for COPY FROM SELECT create_table_cols ('from_tab_1', 1); SELECT create_table_cols ('from_tab_10', 10); ALTER TABLE from_tab_1 SET ACCESS METHOD blackhole_am; ALTER TABLE from_tab_10 SET ACCESS METHOD blackhole_am; Then I have run a set of tests using HEAD, v7 and v10 with queries like that (adapt them depending on the format and table): COPY to_tab_1 TO '/dev/null' WITH (FORMAT text) \watch count=3D5 SET client_min_messages TO error; -- for blackhole_am COPY from_tab_1 FROM '/tmp/to_tab_1.txt' with (FORMAT 'text') \watch count= =3D5 COPY from_tab_1 FROM '/tmp/to_tab_1.bin' with (FORMAT 'binary') \watch coun= t=3D5 All the patches have been compiled with -O2, without assertions, etc. Postgres is run in tmpfs mode, on scissors, without fsync. Unlogged tables help a bit in focusing on the execution paths as we don't care about WAL, of course. I have also included v7 in the test of tests, as this version uses more simple per-row callbacks. And here are the results I get for text and binary (ms, average of 15 queries after discarding the three highest and three lowest values): test | master | v7 | v10 =20 -----------------+--------+------+------ from_bin_1col | 1575 | 1546 | 1575 from_bin_10col | 5364 | 5208 | 5230 from_text_1col | 1690 | 1715 | 1684 from_text_10col | 4875 | 4793 | 4757 to_bin_1col | 1717 | 1730 | 1731 to_bin_10col | 7728 | 7707 | 7513 to_text_1col | 1710 | 1730 | 1698 to_text_10col | 5998 | 5960 | 5987 I am getting an interesting trend here in terms of a speedup between HEAD and the patches with a table that has 10 attributes filled with integers, especially for binary and text with COPY FROM. COPY TO binary also gets nice numbers, while text looks rather stable. Hmm. These were on my buildfarm animal, but we need to be more confident about all this. Could more people run these tests? I am going to do a second session on a local machine I have at hand and see what happens. Will publish the numbers here, the method will be the same. [1]: https://github.com/michaelpq/pg_plugins/tree/main/blackhole_am -- Michael --/Gc+32m0Y099A10m Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmW6+qYACgkQnvQgOdby QH2//RAAoLZRXOSUoJD/EdCqKjwPfUtfMhyvriTwexIjKdzemcnmtIc1JH0CvFCv sD/c47DHNmmnZCQ5TiC/PQ4ogBrKaggcc2RcJermV4030Voh35VZpYIVXBHWqvyN e54wXbcMLCVddVQ1382DSA/pKjXA9Gih/33W8NFXFAR2aBLH5rKbqH9P+Y9cO7u4 q5tSp84rUUcjF8wjRsEWZot0gvCGY4KB5tz7QsGJvA3tkogBE7KlJz+lVz8dHP6B 7DgtN14gSABBJWgiWWrawsXjqBCpuUzLpgFFdORwMadgxDLd/i4F97t19qW23uJ8 CVQ1tyBGJqhyqGdbAqooi90XkcBZHq4qZ5C2YZQ1c0QXuTvjtpZ667isnleGPvVh Rl4BjgesHDK1+JxHYJiLCFJ9KZyPyyOR4/O1aIJcJoscHuTb0SqXwzWGo6TL5NHT yLsTEJShHOdzfCqWIWZsNt0sTeUzE2S3nYXJ6mGaTSZBNrC7bHHCvoL/jH8GNsnh P7lbw0Zz00PoV2GYRgcNBtvUYDoZaxhkHEFIs7UeorqcMxcF1JA/sy/uWypfzMNZ RB22+6lyaH7D8V3djndXO8dXas+IKRepYx4DP9pD44Wh/8QnzuYA9bEAKVds7GqK uCSalA8u5zhBaWyphu2vE+bu5XrNza3s/NLkTma/6Dm4b8yW4sc= =cBJr -----END PGP SIGNATURE----- --/Gc+32m0Y099A10m--