Re: [PATCHES] libpq events patch (with sgml docs) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [PATCHES] libpq events patch (with sgml docs)
Date
Msg-id 28673.1221622817@sss.pgh.pa.us
Whole thread Raw
In response to Re: [PATCHES] libpq events patch (with sgml docs)  (Andrew Chernow <ac@esilo.com>)
Responses Re: [PATCHES] libpq events patch (with sgml docs)  (Andrew Chernow <ac@esilo.com>)
List pgsql-hackers
Andrew Chernow <ac@esilo.com> writes:
> Tom Lane wrote:
>> Looking at this now.  Question: why does PQgetResult invoke the
>> RESULTCREATE event only for non-error results?  

> It didn't seem useful to have the eventproc implementation allocate its private 
> storage (or do whatever prep work it does), just to have it PQclear'd once the 
> user gets the dead result back.  I guess we figured an error result typically 
> has a short life-span, not very useful outside of indicating an error.

Well, you could do a PQresultStatus and skip any prep work if you
actually saw a need to micro-optimize such cases.

> It is odd.  Actually, it looks like a bug to me.  PQgetResult is the
> behavior we were after, don't trigger the event if the creation
> failed.  Same thing occurs during a conn reset.  Looks like PQclear
> needs to check resultStatus before it triggers RESULTDESTROY events.

If you did that, then you WOULD have a bug.  Consider case where you
successfully init two events, and the third one fails.  You'll now
change the result's status to ERROR.  If you don't RESULTDESTROY
then the first two events will leak whatever storage they allocated.

The reason I suggested not being conditional about the init call was
to reduce the probability of bugs of similar ilks associated with
an event proc assuming that it could only get a DESTROY call for
something it had seen CREATEd --- for example, if it were frobbing
a reference count for some long-lived data, it could very easily
screw up the reference count that way.  I suppose that the risk of
an earlier event proc failing means it has to cope with that case
anyway, but I don't think it's a particularly good idea to have
arbitrary asymmetries increasing the odds of a problem.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Common Table Expressions (WITH RECURSIVE) patch
Next
From: Andrew Chernow
Date:
Subject: Re: [PATCHES] libpq events patch (with sgml docs)