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 1tpWCs-0071ch-Gk for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 17:37:26 +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 1tpWCq-003X67-Hh for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 17:37:24 +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 1tpWCq-003X5y-62 for pgsql-hackers@lists.postgresql.org; Tue, 04 Mar 2025 17:37:24 +0000 Received: from mail-yb1-xb36.google.com ([2607:f8b0:4864:20::b36]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpWCm-000wHs-2b for pgsql-hackers@postgresql.org; Tue, 04 Mar 2025 17:37:23 +0000 Received: by mail-yb1-xb36.google.com with SMTP id 3f1490d57ef6-e461015fbd4so4194457276.2 for ; Tue, 04 Mar 2025 09:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; t=1741109840; x=1741714640; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ny4fReuGg71UR4DHTfhPxT+VEfdNxbdAg1N+6UyFjIo=; b=K+xc35jUZjiXd3iLLJwHPKsFz+2m5KNlXRq2ysOPsqIyXudtt7LoN7fkMmLkqlHFkc ngiEe/Oc9BTTA1z6aWS0EOoOPyollhMn5x6wV4q6BpHR2jVmXwIS+/CPajumvSHnDQ1T Xyl+laYKtxHCCi0JJYbCRiBqSorXw61PgOPsc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741109840; x=1741714640; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ny4fReuGg71UR4DHTfhPxT+VEfdNxbdAg1N+6UyFjIo=; b=qYH11/3eaYL36LmX9n+nOIwN7UAPIe1XOcjVSvosWLK1Oj8sp1xgwIviX5AnzVjYNI LmD9jpZRmMEUtQJgpRYvPlrEGeFW8z9gDkhe44WyA+qNZHJZHLcfIv83dGd8lOTk1lKc r9ZwMBpp8/BrZCu3NVUnCqJdOhsL2PGBvXR/DI2lqhdyiowIeK204OEt4OuZkBD0QIeu vTaX1JGgwoPz7lMtzLXPwsQU+2K2y4HCsGs1krzSorR6glIKCpkJbM70ZMv6HcJTPRtu IunHflf+p4zOQMCDTg6MGvFwbSB/I8sEDMPNmVh5mlH5mrlS29E07Km/tHL7bEx9JEpl cCJA== X-Forwarded-Encrypted: i=1; AJvYcCXzZKobnh4w95FLDtmXn0dB+4ZxgE5QyboIMTG+CNsiMb65ci4BV254Edw5kngE3rE9VXl4gIruEoNPOjjK@postgresql.org X-Gm-Message-State: AOJu0YzETyy7g14yOx6HKSm6zuZM4sKTlvTgTgdwJmdJe9YU9H3rYLU2 cT9aclaJ74jfQg6JGCglgUzOkQ8AzsDFwNvMaMLilRVQH9JfjxZ/KWi28KIIhf74FSn3Hjagply U4/lJi6G2a7brPIQ/pO/b/UPS34yWMn2aGqdRdw== X-Gm-Gg: ASbGncsoDh5MiUU4o2f9L2pjwjUgqM8jGOiG184z1NmsyRd1m7VY5t5xUjupKlCA3RG yUewxWgV7VvlKYP2veVY7xadsDuGvnk2Ke3oLeAH0p+qcjomnu7ZCtd9JRZHDOiPmbFTpJZloe7 ZvFWQShZhthn4dFSSeAK7Ue8X6XzCaozeFa4eJct3YtcEX6X1aoCEbur8t6Q== X-Google-Smtp-Source: AGHT+IFX+fXZuDfGbIe3aNYrRymKpnwK1sGwDaLLz8beOjZGpe+5NGz9Uohhj6Os86bOn3VHbjudfkYbhRT5FSVkdl8= X-Received: by 2002:a05:6902:3209:b0:e60:89bc:6e11 with SMTP id 3f1490d57ef6-e60b2f30db3mr19964819276.42.1741109840287; Tue, 04 Mar 2025 09:37:20 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Anthonin Bonnefoy Date: Tue, 4 Mar 2025 18:37:09 +0100 X-Gm-Features: AQ5f1Jqe4Du6INDG6aZLrqpjz4kE4_D0T_Guelc4qM1Fj_O1gCZqabBj4Ek6EBo Message-ID: Subject: Re: Add Pipelining support in psql To: Daniel Verite Cc: Michael Paquier , Jelte Fennema-Nio , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 4, 2025 at 1:32=E2=80=AFPM Daniel Verite wrote: > But if the code triggered the use of the extended query protocol > if \bind is in effect *or* a pipeline is active, then the first sequence > would just push "select 1" into the pipeline. > > This would have the advantage that, to submit into a pipeline > a pre-existing file with SQL commands separated with ";" you don't have > to pre-process it to inject metacommands. Adding a \startpipeline at > the beginning and an \endpipeline at the end would be sufficient in the > cases that the user does not need the results before the end. > > The \sendpipeline is not mandatory when ";" can be used to terminate > the queries. But it makes it clearer that the script wants > specifically to push into a pipeline, and it might accept specific > options in the future, whereas obviously ";" cannot. So if I understand correctly, you want to automatically convert a simple query into an extended query when we're within a pipeline. That would be doable with: --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -1668,7 +1668,16 @@ ExecQueryAndProcessResults(const char *query, } break; case PSQL_SEND_QUERY: - success =3D PQsendQuery(pset.db, query); + if (PQpipelineStatus(pset.db) !=3D PQ_PIPELINE_OFF)= { + success =3D PQsendQueryParams(pset.db, quer= y, + pset.bind_nparams, NULL, + (const char *const *) pset.bind_params, + NULL, NULL,= 0); + if (success) + pset.piped_commands++; + } + else + success =3D PQsendQuery(pset.db, query); break; } I do see the idea to make it easier to convert existing scripts into using pipelining. The main focus of the initial implementation was more on protocol regression tests with psql, so that's not necessarily something I had in mind. I have some reservation as it will push all parameters in the query string which may not be the desired behaviour. But on the other hand, if it is to convert existing psql scripts, then everything was already pushed as simple queries. Plus, this is similar to what pgbench is doing when using -Mextended or -Mprepared.