pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Alvaro Herrera <alvaro.herrera@2ndquadrant.com>
To: Boris Kolpackov <boris@codesynthesis.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Pipeline mode and PQpipelineSync()
Date: Wed, 7 Jul 2021 13:30:46 -0400
Message-ID: <202107071730.vkyej2goquhp@alvherre.pgsql> (raw )
In-Reply-To: <boris.20210707170157@codesynthesis.com >
On 2021-Jul-07, Boris Kolpackov wrote:
> // Try to minimize the chance of blocking the server by first processing
> // the result and then sending more queries.
> //
> if (FD_ISSET (sock, &rds))
> {
> if (PQconsumeInput (conn) == 0)
> assert (false);
>
> while (PQisBusy (conn) == 0)
> {
> //fprintf (stderr, "PQgetResult %zu\n", rn);
>
> PGresult* res = PQgetResult (conn);
> assert (res != NULL);
> ExecStatusType stat = PQresultStatus (res);
Hmm ... aren't you trying to read more results than you sent queries? I
think there should be a break out of that block when that happens (which
means the read of the PGRES_PIPELINE_SYNC needs to be out of there too).
With this patch, the program seems to work well for me.
***************
*** 94,112 ****
while (PQisBusy (conn) == 0)
{
//fprintf (stderr, "PQgetResult %zu\n", rn);
PGresult* res = PQgetResult (conn);
assert (res != NULL);
ExecStatusType stat = PQresultStatus (res);
- if (stat == PGRES_PIPELINE_SYNC)
- {
- assert (wdone && rn == n);
- PQclear (res);
- rdone = true;
- break;
- }
-
if (stat == PGRES_FATAL_ERROR)
{
const char* s = PQresultErrorField (res, PG_DIAG_SQLSTATE);
--- 94,110 ----
while (PQisBusy (conn) == 0)
{
//fprintf (stderr, "PQgetResult %zu\n", rn);
+ if (rn >= wn)
+ {
+ if (wdone)
+ rdone = true;
+ break;
+ }
PGresult* res = PQgetResult (conn);
assert (res != NULL);
ExecStatusType stat = PQresultStatus (res);
if (stat == PGRES_FATAL_ERROR)
{
const char* s = PQresultErrorField (res, PG_DIAG_SQLSTATE);
***************
*** 190,195 ****
--- 188,201 ----
break; // Blocked or done.
}
}
+
+ if (rdone)
+ {
+ PGresult *res = PQgetResult(conn);
+ assert(PQresultStatus(res) == PGRES_PIPELINE_SYNC);
+ PQclear(res);
+ break;
+ }
}
if (PQexitPipelineMode (conn) == 0 ||
***************
*** 246,248 ****
--- 252,269 ----
PQclear (res);
}
}
+
+ int main(int argc, char **argv)
+ {
+ PGconn *conn = PQconnectdb("");
+ if (PQstatus(conn) != CONNECTION_OK)
+ {
+ fprintf(stderr, "connection failed: %s\n",
+ PQerrorMessage(conn));
+ return 1;
+ }
+
+ test(conn);
+ }
+
+
--
Álvaro Herrera Valdivia, Chile — https://www.EnterpriseDB.com/
view thread (41+ messages) latest in thread
Message-ID: <202107071730.vkyej2goquhp@alvherre.pgsql>
Permalink: ../202107071730.vkyej2goquhp@alvherre.pgsql/
Also on: postgresql.org/message-id/202107071730.vkyej2goquhp@alvherre.pgsql
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: alvaro.herrera@2ndquadrant.com, boris@codesynthesis.com, pgsql-hackers@lists.postgresql.org
Subject: Re: Pipeline mode and PQpipelineSync()
In-Reply-To: <202107071730.vkyej2goquhp@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox