Thread: libpq: why only one PQsendQuery per connection at a time?

libpq: why only one PQsendQuery per connection at a time?

From
sftf-misc@mail.ru
Date:
Hello!
Question generally to (libpq) developers.

According to http://www.postgresql.org/docs/9.4/static/libpq-async.html:
"PQsendQuery cannot be called again (on the same connection) until PQgetResult
has returned a null pointer, indicating that the command is done."

As I guess this is also true for all PQsend* functions, like PQsendQueryPrepared,
although this is not explicitly stated in the documentation.

So question is why this limitaion exists?

Why PQgetResult(PGconn *conn) operates on connection,
and not on some unique handler that each "PQsend*" could return.

Is it limitaion of libpq or architecture of postgresql backend or backend-frontend protocol?



Re: libpq: why only one PQsendQuery per connection at a time?

From
David G Johnston
Date:
sftf-2 wrote
> So question is why this limitaion exists?
>
> Why PQgetResult(PGconn *conn) operates on connection,
> and not on some unique handler that each "PQsend*" could return.
>
> Is it limitaion of libpq or architecture of postgresql backend or
> backend-frontend protocol?

IIUC this is a backend Postgres limitation - it was designed in a least
complex way where each process acts in a serial fashion.  A single process
has no way to maintain concurrent state for multiple active queries.

David J.



--
View this message in context:
http://postgresql.nabble.com/libpq-why-only-one-PQsendQuery-per-connection-at-a-time-tp5832803p5832807.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: libpq: why only one PQsendQuery per connection at a time?

From
Dmitry Igrishin
Date:


2015-01-04 19:02 GMT+03:00 <sftf-misc@mail.ru>:
Hello!
Question generally to (libpq) developers.

According to http://www.postgresql.org/docs/9.4/static/libpq-async.html:
"PQsendQuery cannot be called again (on the same connection) until PQgetResult
has returned a null pointer, indicating that the command is done."

As I guess this is also true for all PQsend* functions, like PQsendQueryPrepared,
although this is not explicitly stated in the documentation.

So question is why this limitaion exists?
Because it's violates the protocol -- sending messages like Parse or Bind to the backend
until the CommandComplete or ErrorResponse consumed by the frontend is wrong.


Why PQgetResult(PGconn *conn) operates on connection,
and not on some unique handler that each "PQsend*" could return.
It does not make sense because of the message flow described by the protocol.

Is it limitaion of libpq or architecture of postgresql backend or backend-frontend protocol?

PS. If you need pipelining  take a look at the thread "libpq pipelining" in hackers-.


--
// Dmitry.