X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 99003DA957 for ; Fri, 21 Oct 2005 18:51:56 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03822-03 for ; Fri, 21 Oct 2005 21:51:50 +0000 (GMT) Received: from halfgaar.kicks-ass.net (cc503261-a.eelde1.dr.home.nl [217.121.237.58]) by svr1.postgresql.org (Postfix) with ESMTP id 9D1C4DA8A9 for ; Fri, 21 Oct 2005 18:51:51 -0300 (ADT) Received: from localhost ([127.0.0.1]) by halfgaar.kicks-ass.net with esmtp (Exim 4.50) id 1ET4np-00059f-Oe; Fri, 21 Oct 2005 23:51:53 +0200 Message-ID: <435962F9.40607@gmail.com> Date: Fri, 21 Oct 2005 23:51:53 +0200 From: Wiebe Cazemier User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050729) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-sql@postgresql.org Subject: Re: Delete rule chain stops unexpectedly References: <4358F79B.1000409@gmail.com> <21436.1129905772@sss.pgh.pa.us> <435902DC.3000807@gmail.com> <23325.1129910791@sss.pgh.pa.us> In-Reply-To: <23325.1129910791@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.394 required=5 tests=[AWL=-0.448, FORGED_RCVD_HELO=0.05, RCVD_IN_NJABL_DUL=1.655, RCVD_IN_SORBS_DUL=0.137] X-Spam-Level: * X-Archive-Number: 200510/249 X-Sequence-Number: 23102 Tom Lane wrote: >>A quote from the postgresql manual: > >>"But for ON UPDATE and ON DELETE rules, the original query is done after the >>actions added by rules. This ensures that the actions can see the to-be-updated >>or to-be-deleted rows" > > Yes, I know that quote. I wrote it. It's not relevant here because the > original query (the delete against the view) is never done at all, since > you have a DO INSTEAD rule. What is relevant is the timing of the > delete issued against the underlying table, and you have that scheduled > to occur too early because the rule that does it is first in > alphabetical order. Oh yeah, whoops, I was under a false impression of what the original query was... > Because the rule converts those inserts into, effectively, > > INSERT INTO debuglog SELECT ... WHERE EXISTS(some matching OLD row); > > and there are no longer any matching OLD rows in the view. (If it > didn't act that way then the INSERTs would execute even for a "DELETE > WHERE false". If you find any of this surprising or not what you want, > you should probably be using triggers not rules.) Ah, I see. I'll convert them to triggers, or just put the delete at the end. I could even put all this in one rule, that would be easier. > > >>Or, that all the rules _are_ >>executed when I call the query with "explain analayze". > > > Hmm ... this appears to be a bug in EXPLAIN ANALYZE: it really should > bump the CommandCounter between plan trees, but fails to ... Is this something I have to report?