From: | Richard Yen <dba(at)richyen(dot)com> |
---|---|
To: | pgsql-performance(at)postgresql(dot)org |
Subject: | PQisBusy behaving strangely |
Date: | 2009-05-21 00:07:09 |
Message-ID: | 88B33787-0A81-4FBE-96EC-CCE7F65A7576@richyen.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Hi All,
Not sure if this is the right pgsql-* "channel" to post to, but I was
hoping maybe someone could answer a question from one of my fellow
developers. Please read below:
> So, following the documentation, we wrote a little ASYNC version of
> exec. here is the code:
>
> PGresult *PGClient::exec(char *query) {
> PGresult *result;
>
> if (conn == NULL) {
> ERROR("PGClient calling exec when a connection hasn't been
> established yet");
> return NULL;
> }
> if (PQsendQuery(conn,query)==0) {
> ERROR("PGClient wasn't able to sendQuery");
> return NULL;
> }
> int socketFD = PQsocket(conn);
> pollfd pfd;
> pfd.fd = socketFD;
> pfd.events = POLLIN|POLLRDHUP;
> consumeSome:
> if (poll(&pfd,1,PG_EXEC_TIMEOUT*1000) == 0) {
> ERROR("PGClient is timing out ");
> return NULL;
> }
> if (PQconsumeInput(conn)==0) {
> ERROR("PGClient detected trouble when trying to consumeInput");
> return NULL;
> }
> if (PQisBusy(conn))
> goto consumeSome;
> result = PQgetResult(conn);
> if (PQisBusy(conn)) {
> // something is wrong, because this is telling us that there is
> more data on the way,
> but there shouldn't be.
> ERROR("PGClient had a weird case where more data is on its way");
> }
> PGresult *tempResult=PQgetResult(conn);
> if (tempResult!=0) {
> // we either had multiple SQL queries that return multiple
> results or something weird
> happened here, caller should close connection
> ERROR("PGClient had a weird case where multiple results were
> returned");
> }
> return result;
> }
>
> So, assuming that every query we pass in is just a simple, 1 result-
> set-returning query, we should never see PQisBusy returning a non-
> NULL after we do the PQgetResult. BUT every now and then, in our
> code, the PQisBusy function returns a non-NULL and we get that
> ERROR("PGClient had a weird case where more data is on its way")...
> BUT when we do tempResult=PQgetResult, then it is ALWAYS null... can
> someone please explain how PQisBusy can return true (when we aren't
> expecting it to) but then PQgetResult returns nothing?
If there's any knowledge of why PQisBusy returns not-null, yet nothign
comes our of PQgetResult, could you let me know what's going on?
Any help much appreciated!
--Richard
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2009-05-21 03:09:52 | Re: postgresql.conf suggestions? |
Previous Message | Kobby Dapaah | 2009-05-20 16:22:21 | postgresql.conf suggestions? |