Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B1668650329 for ; Wed, 17 Sep 2008 00:50:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 54597-03-6 for ; Wed, 17 Sep 2008 00:50:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id EF63C650365 for ; Wed, 17 Sep 2008 00:40:22 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m8H3eHRr028674; Tue, 16 Sep 2008 23:40:18 -0400 (EDT) To: Andrew Chernow cc: Alvaro Herrera , PostgreSQL-development , Merlin Moncure Subject: Re: [PATCHES] libpq events patch (with sgml docs) In-reply-to: <48D072E3.6010703@esilo.com> References: <48C18533.2000204@esilo.com> <20080905192215.GK4353@alvh.no-ip.org> <48C18B48.509@esilo.com> <20080905194853.GL4353@alvh.no-ip.org> <48C191A7.3000205@esilo.com> <20080905201504.GM4353@alvh.no-ip.org> <48C19759.90402@esilo.com> <27615.1221619326@sss.pgh.pa.us> <48D072E3.6010703@esilo.com> Comments: In-reply-to Andrew Chernow message dated "Tue, 16 Sep 2008 23:00:51 -0400" Date: Tue, 16 Sep 2008 23:40:17 -0400 Message-ID: <28673.1221622817@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200809/1075 X-Sequence-Number: 124204 Andrew Chernow 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