Re: PQisBusy() always returns TRUE - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: PQisBusy() always returns TRUE
Date
Msg-id 20050115202758.GD22775@svana.org
Whole thread Raw
In response to Re: PQisBusy() always returns TRUE  (ntinos@aueb.gr)
Responses Re: PQisBusy() always returns TRUE
List pgsql-general
On Sat, Jan 15, 2005 at 09:50:35PM +0200, ntinos@aueb.gr wrote:
> If understand correctly what you are saying, the right code for this thing
> is:
>
> PQconsumeInput(conn);        //Try to collect the results
> while (PQisBusy(conn))       // while not ready ...
>     PQconsumeInput(conn); //...retry
>
> res=PQgetResult(conn);       // Now get the results
>
> I tried this and it worked. However, the problem now is that it is slow
> (surely slower than using blocking commands).
> If the code above is right (?), why is that?

The purpose of non-blocking commands is so you can do something else
useful in the meantime. The above is probably slower because you're
using all your CPU time spinning in a loop.

I belive if you're waiting in an event loop, you can use PQsocket() to
return the fd to use in select. Or if you're doing other work, do that
while you're waiting and check isBusy when you have time...

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: OID Usage
Next
From: Edmund Dengler
Date:
Subject: Multi-column indexes