Re: Docs patch to note that rules only get run once per query. - Mailing list pgsql-docs

From Jan Wieck
Subject Re: Docs patch to note that rules only get run once per query.
Date
Msg-id 3E9A999D.82FA4835@Yahoo.com
Whole thread Raw
In response to Docs patch to note that rules only get run once per query.  (Sean Reifschneider <jafo@tummy.com>)
List pgsql-docs
Tom Lane wrote:
>
> Sean Reifschneider <jafo@tummy.com> 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 #


pgsql-docs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Docs patch to note that rules only get run once per query.
Next
From: Curt Sampson
Date:
Subject: Re: 6.8.5: Location of CURRENT_DATE unclear