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 1rX9qd-0094JD-NN for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Feb 2024 01:02: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 1rX9qb-00Gv4O-Na for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Feb 2024 01:02:01 +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 1rX9qZ-00Gv4F-UF for pgsql-hackers@lists.postgresql.org; Tue, 06 Feb 2024 01:02:01 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rX9qW-005fip-BW for pgsql-hackers@postgresql.org; Tue, 06 Feb 2024 01:01:59 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id DAC375C007B; Mon, 5 Feb 2024 20:01:54 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 05 Feb 2024 20:01:54 -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=1707181314; x=1707267714; bh=PU2OYC0/GB DGH4p6jNFT4y7Wu/9q9jGIh4vgdsSxU48=; b=GLwIGeqTnoJMn9oMgolRer6fmy J7NWttXK6sLgpEVqjtNz46nfeAtQqc7WDfmWvfptVCu2JKNa3pzC5y7YpP/NZmWg 272dNajouxce77LAuYXA+tFR6if3VQ/jxPH9FSD1ow0AcIjnvee1fiwSWtB2dPsb dL632es2s2uq2lUv6PE0/RsCZCtKL3hGsyeyXrf9QWyViXKF9vCBHhMMuXTpfKU1 UsXbOk/cpurZczTyDSMjmB86MBZ8KzOQY3zj2MGSZHPd+tAD1Da4NsKTV0V/ZcgF OCnCe1T6kiybHVBV1Nd3TdNIW8yRFQSArPkz+P4OxL1WMk5vGFnz2Gx0AmmQ== 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=1707181314; x=1707267714; bh=PU2OYC0/GBDGH4p6jNFT4y7Wu/9q 9jGIh4vgdsSxU48=; b=OnZHmJsfJG6SOAvqJ+YLYCxZ7etm6Uwb3jXmxEcmVuAI 9YTQzElQZh9ewvUG6gmCQbPsHiA1/wa7BanAMDDSDLC5ECwNvWY0IW4tMVjvhnO3 FeqPUK/j5hytT0U8VOJlAbex9UU8IbSvpkoa8644l4ZXmp4a9cRhSPiQhOjOVUXA vVB6ldTGD5568uh5t0j9b9cl6GZAh/RQwEEOqKgKIBr2mcQFHMEG9ip4VdoTXJ0G GyL860YQT5+eTBUcnJgLljLr4kmvfO/2rNv8qMK+bPRr4xLrAg7mf0ItPPxJiGBD Wol3EHuCJy4t20s0pv5eURZNzMvGTXAAe1xLiPR86w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvvddgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepgeffjeevgfevuddvjedtvddt ieejheduueelvddufedtgfefjedvkeevkeeivddvnecuffhomhgrihhnpehpohhsthhgrh gvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Feb 2024 20:01:50 -0500 (EST) Date: Tue, 6 Feb 2024 10:01:36 +0900 From: Michael Paquier To: Andres Freund Cc: Sutou Kouhei , 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: <20240202.163319.975394400703526633.kou@clear-code.com> <20240202.174618.349091157390883477.kou@clear-code.com> <20240205182118.h5rkbnjgujwzuxip@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="yw7GqxmVywdAlt9E" Content-Disposition: inline In-Reply-To: <20240205182118.h5rkbnjgujwzuxip@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --yw7GqxmVywdAlt9E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Feb 05, 2024 at 10:21:18AM -0800, Andres Freund wrote: > Have you benchmarked the performance effects of 2889fd23be5 ? I'd not at all > be surprised if it lead to a measurable performance regression. Yes, I was looking at runtimes and some profiles around CopyOneRowTo() to see the effects that this has yesterday. The principal point of contention is CopyOneRowTo() where the callback is called once per attribute, so more attributes stress it more. The method I've used is described in [1], where I've used up to 50 int attributes (fixed value size to limit appendBinaryStringInfo) with 5 million rows, with shared_buffers large enough that all the data fits in it, while prewarming the whole. Postgres runs on a tmpfs, and COPY TO is redirected to /dev/null. For reference, I still have some reports lying around (-g attached to the backend process running the COPY TO queries with text format), so here you go: * At 95fb5b49024a: - 83.04% 11.46% postgres postgres [.] CopyOneRowTo - 71.58% CopyOneRowTo - 30.37% OutputFunctionCall + 27.77% int4out + 13.18% CopyAttributeOutText + 10.19% appendBinaryStringInfo 3.76% 0xffffa7096234 2.78% 0xffffa7096214 + 2.49% CopySendEndOfRow 1.21% int4out 0.83% memcpy@plt 0.76% 0xffffa7094ba8 0.75% 0xffffa7094ba4 0.69% pgstat_progress_update_param 0.57% enlargeStringInfo 0.52% 0xffffa7096204 0.52% 0xffffa7094b8c + 11.46% _start * At 2889fd23be56: - 83.53% 14.24% postgres postgres [.] CopyOneRowTo - 69.29% CopyOneRowTo - 29.89% OutputFunctionCall + 27.43% int4out - 12.89% CopyAttributeOutText pg_server_to_any + 9.31% appendBinaryStringInfo 3.68% 0xffffa6940234 + 2.74% CopySendEndOfRow 2.43% 0xffffa6940214 1.36% int4out 0.74% 0xffffa693eba8 0.73% pgstat_progress_update_param 0.65% memcpy@plt 0.53% MemoryContextReset + 14.24% _start If you have concerns about that, I'm OK to revert, I'm not wedded to this level of control. Note that I've actually seen *better* runtimes. [1]: https://www.postgresql.org/message-id/Zbr6piWuVHDtFFOl@paquier.xyz > I think callbacks for individual attributes is the wrong approach - the > dispatch needs to happen at a higher level, otherwise there are too many > indirect function calls. Hmm. Do you have concerns about v13 posted on [2] then? If yes, then I'd assume that this shuts down the whole thread or that it needs a completely different approach, because we will multiply indirect function calls that can control how data is generated for each row, which is the original case that Sutou-san wanted to tackle. There could be many indirect calls with custom callbacks that control how things should be processed at row-level, and COPY likes doing work with loads of data. The End, Start and In/OutFunc callbacks are called only once per query, so these don't matter AFAIU. [2]: https://www.postgresql.org/message-id/ZcFz59nJjQNjwgX0@paquier.xyz -- Michael --yw7GqxmVywdAlt9E Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmXBhPAACgkQnvQgOdby QH3S6Q//Vn1Tp6cynshkLif2+4aizJ6YmzCgTFOVPXjTBxRmR81LWLv0PmfYlOX2 qIMK25W2DkndRsetNQBIYoDZBfpnqhoT9M/QQYHweiR4fSsIvEDrfZr0WiuncQCJ TCjhaNGul2T1gEzncXZCV6C55IZATPxA75XkVkpe+OOc71FMBuNa+iAB7qd+VALm 3DqNJPuPvH+IP4l0UIGPLssmrz45GwO2nBiy5b4JacAv+xMT1xKK3cZ380EsgRXn LYU44DUOIns+QZahAM6c5GrFhextJMzDk+JviEGenFAwe2H3jX8TBWCoS4Wry3Pp 48GafDy/0RdE9KkqXuPjpBowWZAjItFz4BoPWQpxhlY49oligjofbQDlaKtmwCiS biB4MDuUf+x6CHUAd9rSpw7J/v82e0k6ti/vfpUH2zxUsy1tkBHUxPmRCCl0hkXW XoJEQSTbP3Iy3J4FoS60ozrJgpTxuF473DZbl6w99L9txKy0jlfU9lT8e02ELjdw zu8ez18J3khW6nWwGtYsRxKoiFlir4UcvsdV58+omlZdIPWhF2HUi6BKXChAImeF 6zVmsvACxuHOuYkRL+uPYCgsxX1oDEA20N1nxuoSDsa12tbTfiHiiCe1Hbh7VYgj wy/4dEFVZ5vlByB/Zl1OSlKSxk7Qe+JdQwWB0BV1VRsY5DH3ptU= =8xCq -----END PGP SIGNATURE----- --yw7GqxmVywdAlt9E--