X-Original-To: pgsql-docs@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 72391475A80 for ; Mon, 14 Apr 2003 07:21:00 -0400 (EDT) Received: from europa.janwieck.net (h00045a2e4e7c.ne.client2.attbi.com [24.131.181.55]) by postgresql.org (Postfix) with ESMTP id 8EEBD4758E6 for ; Mon, 14 Apr 2003 07:20:59 -0400 (EDT) Received: from Yahoo.com (linksys.janwieck.net [192.168.192.1]) (authenticated) by europa.janwieck.net (8.11.6/8.11.6) with ESMTP id h3EBLLa28226; Mon, 14 Apr 2003 07:21:21 -0400 Message-ID: <3E9A999D.82FA4835@Yahoo.com> Date: Mon, 14 Apr 2003 07:21:01 -0400 From: Jan Wieck Organization: Home X-Mailer: Mozilla 4.8 [en] (Windows NT 5.0; U) X-Accept-Language: en,ru MIME-Version: 1.0 To: Tom Lane Cc: Sean Reifschneider , pgsql-docs@postgresql.org Subject: Re: Docs patch to note that rules only get run once per query. References: <20030413234349.GF7507@tummy.com> <1569.1050292052@sss.pgh.pa.us> <20030414035829.GI7507@tummy.com> <1756.1050293515@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-28.5 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/26 X-Sequence-Number: 1752 Tom Lane wrote: > > Sean Reifschneider writes: > > On Sun, Apr 13, 2003 at 11:47:32PM -0400, Tom Lane wrote: > >> So I feel dissatisfied with the above "clarification". Can you think > >> of another way to explain it? > > > Unfortunately, I really don't understand it... My first thought was > > that it was a bug, but when I presented it to the bugs list they said > > that the rule only gets executed once per query and that triggers should > > be used if you want to run on every impacted row. > > Well, it could be argued that the present rule behavior is buggy, not > because there's anything wrong with it on its own terms, but just > because too many people don't understand it :-( > > Jan, can you offer any words of wisdom here? I'm not subscribed to docs, so I missed the original discussion. My guess is that the concept of query rewriting, or productional rules it was originally called, is just not that easy to understand. It can do something else, it can do it conditionally, it can do it for multiple rows at once and you have access to NEW and OLD ... the natural conclusion is that it works on the row level ... but it doesn't. As a matter of fact "rules" are not "executed" at all. They describe "modifications" that are applied to queries before anything is executed. It is allways a mixture between the original query and the rule(s) that get's executed. And in the case of updateable views, the views RIR rule is *allways* part of that. My hardest attempt to describe how it works is Chapter 13 of Section II of the PostgreSQL Programmers Guide, also known as the Al Bundy database. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #