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 1tkHwn-002LYa-OJ for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 07:23:14 +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 1tkHwm-007bSB-6v for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 07:23:12 +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 1tkHwk-007bS3-O2 for pgsql-hackers@lists.postgresql.org; Tue, 18 Feb 2025 07:23:11 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tkHwi-001TJP-1b for pgsql-hackers@postgresql.org; Tue, 18 Feb 2025 07:23:09 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5D0F1114021D; Tue, 18 Feb 2025 02:23:07 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Tue, 18 Feb 2025 02:23:07 -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=1739863387; x=1739949787; bh=wWmSN+Enjv k7nTmnvitzvZ2tUw4EkLXURmLOkwSRavc=; b=O80Sko1olOj3Sf88VtBDI87pan Cs9ko9m0D0og05xS1RfXJUTa9/Kq+kJIRlLY0/JroCYNwDAX8KhrJm+srFSWAZ75 5rsYLzUkH01btYB3lDsE5YpFP2lgeBJe7Wlw0Lfk3XHutLGrpbTJoHUPZ+tO1Wgf WG0Egk3quWnhXNov9Tcqq5uMHXkLbtTufL9x+90KnDFVX+IKBGHCNDFrkKjJzc2m cDL5Uc3xmilBnL7bRxV9tsu53oXKHheK3AAN6iMhZm5cZt2l8I2UW7sAPtJE0Y9G bo1wmFd5KXMuoS4j3wESGwsKOV0Ayss27Z71VAnNPjX6u/tkhdwuEfDID3sQ== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1739863387; x=1739949787; bh=wWmSN+Enjvk7nTmnvitzvZ2tUw4EkLXURmL OkwSRavc=; b=x6da6LdX6BdYcdpdBzHm12RaE8GoJe4OC1eo4GN04GGWbydPYG1 V+KG5YnwDOKphlRONl9yZdMQIDp0XnPkSN1dxI/4YzbAcbI56+/z6wqNkdVSg+3V WDYyupadxvN0IngJzxcvu+nP8aaVQTc6f4iGKcITCcoU72PDJWjQa6bNVJCvG8zT 2/uORVE+afnnhms8tGF3Xzo8z5tzerO/u54wfxronM3QeWnAyZZLNdxuenwgKKBz 8KZRZpDr2oP+7kx6IanpGdc5urpR9OXw6Qw4bS/ghlppVJgiQM3ieRrTeT/GLAIA bw8tpcFR8BROcP1SuuErVpWXBv9uWCZ00cQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeitdeikecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffk fhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrh cuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeet leeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghl sehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegrnhhthhhonhhinhdrsghonhhnvghfohihsegurghtrgguohhg hhhqrdgtohhmpdhrtghpthhtohepphhoshhtghhrvghssehjvghlthgvfhdrnhhlpdhrtg hpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 18 Feb 2025 02:23:05 -0500 (EST) Date: Tue, 18 Feb 2025 16:22:53 +0900 From: Michael Paquier To: Anthonin Bonnefoy Cc: Jelte Fennema-Nio , PostgreSQL Hackers Subject: Re: Add Pipelining support in psql Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="hphjdLxQZZh4aATV" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --hphjdLxQZZh4aATV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 14, 2025 at 09:49:02AM +0100, Anthonin Bonnefoy wrote: > During my tests, I've noticed I didn't handle query cancellation, this > is now fixed. I've also added additional comments related to > available_results to make it clearer that it depends on what the > server has flushed to the client. This is a pretty cool patch. I like the structure you have used for the integration with the tracking of the number of commands, the number of syncs (like pgbench) put in a pipeline, the number of results requested and the number of results available. That makes the whole easier to look at with a state in pset. + PSQL_SEND_PIPELINE_SYNC, + PSQL_START_PIPELINE_MODE, + PSQL_END_PIPELINE_MODE, + PSQL_FLUSH, + PSQL_SEND_FLUSH_REQUEST, + PSQL_GET_RESULTS, These new values are inconsistent, let's use some more PSQL_SEND_* here. That makes the whole set of values more greppable. The tests in psql.sql are becoming really long. Perhaps it would be better to split that into its own file, say psql_pipeline.sql? The input file is already 2k lines, you are adding 15% more lines to that. + * otherwise, calling PQgetResults will block.=20 Likely PQgetResults =3D> PQgetResult(). Wondering if the cancellation in ExecQueryAndProcessResults() is sound, I've not been able to break it, still.. I can also get behind the additions of \flush and \flushrequest to query different parts of libpq. + if (pset.requested_results =3D=3D 0) + /* We've read all requested results, exit */ + return res; Set of nits with the style of the code, but I'd suggest to use braces {} here, to outline that the comment is in a block. There's a second, larger one in discardAbortedPipelineResults(). + if (strcmp(cmd, "gx") =3D=3D 0 && PQpipelineStatus(pset.db) !=3D PQ_PIPEL= INE_OFF) + { + pg_log_error("\\gx not allowed in pipeline mode"); + clean_extended_state(); + return PSQL_CMD_ERROR; + } What is the reasoning here behind this restriction? \gx is a wrapper of \g with expanded mode on, but it is also possible to call \g with expanded=3Don, bypassing this restriction. Let's split the prompt patch with the support of %P into its own patch. -#define DEFAULT_PROMPT1 "%/%R%x%# " -#define DEFAULT_PROMPT2 "%/%R%x%# " +#define DEFAULT_PROMPT1 "%/%R%P%x%# " +#define DEFAULT_PROMPT2 "%/%R%P%x%# " #define DEFAULT_PROMPT3 ">> " I don't think that changing this default is a good idea. Everybody can do that in their own .psqlrc (spoiler: I do). The idea to use three fields with a hardcoded format does not look like a good idea to me. I think that this should be done in a different and more extensible way: - Use %P to track if we are in pipeline mode on, off or abort. - Define three new variables that behave like ROW_COUNT, but for the fields you want to track here. These could then be passed down to a PROMPT with %:name:, grammar already supported. That would make the whole much more flexible. At it seems to me that we could also add requested_results to this set? These could be named with the same prefix, like PIPELINE_SYNC_COUNT, etc. -- Michael --hphjdLxQZZh4aATV Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAme0NU0ACgkQnvQgOdby QH38iA//UdPubIRO+L52gnX6T21Y7gn8lb3WZJBua93YsUV3XkzHdHEGNENDF1zm u/2Cf8+7fKjgu/ePQO+dX0EEgEhYGVcoOdGCiFysrmTPOHWmH6oAiOspLiTCy7u5 jMI4Du7FVqI4A+mBEQOC904il5Pm/H8yaK1Tgy+PBti/ldSJdSVWHvej74TrI3DN nq6Q+kkrrY0jwwvaSGmFUmTIxRLMO1hr/2ZqkghksRX1JX72zakEV07sW0uqBDW8 2I/vbdjNAuoNk3FOGi5s8FQKoXWtILQ52mnFt922UUyK1XgSnYDqdRRnE1HpbfZ6 JQqchOec8i2MqGEiBpGznPXYo8wneQceoX7lScWEIKGM397jPLHGVHsUExAwQUBa tSqcBS8euf9KbDLiThfZGrDIYQWjOvJcTX3j6S2BTrl0obF3Hg3+GBKJ1lehCn3f XDLI9JP0iYh32HKI5X+4JisrUkfwXIU3HeMlxtyxtE7aeV8mTEswCm87TcAKlDN5 czJFKfxiJBHF9tmrYawRLvwaXGFNjmt5X76M/J+64nKqWIV4v0u+OG7uGZa1SqSz iOI/eehoX9ZMusZMglfzGcQU2m/1gESAJoPsDL8QNAh295Vqy4uNhu4e/D8Iva0l Y6TmPiNiyAupa0UWQcc2Tbvh42sT1lmYV7mt4lSIEcHyO0U+Mis= =qtQq -----END PGP SIGNATURE----- --hphjdLxQZZh4aATV--