Re: [PATCHES] libpq events patch (with sgml docs)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 03:40:17
Message-ID: 28673.1221622817@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Chernow 2008-09-17 03:59:44 Re: [PATCHES] libpq events patch (with sgml docs)
Previous Message Tatsuo Ishii 2008-09-17 03:14:31 Re: Common Table Expressions (WITH RECURSIVE) patch

Browse pgsql-patches by date

  From Date Subject
Next Message Andrew Chernow 2008-09-17 03:59:44 Re: [PATCHES] libpq events patch (with sgml docs)
Previous Message Andrew Chernow 2008-09-17 03:00:51 Re: [PATCHES] libpq events patch (with sgml docs)