Re: Docs patch to note that rules only get run once per query.

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sean Reifschneider <jafo(at)tummy(dot)com>, pgsql-docs(at)postgresql(dot)org
Subject: Re: Docs patch to note that rules only get run once per query.
Date: 2003-04-14 11:21:01
Message-ID: 3E9A999D.82FA4835@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

Tom Lane wrote:
>
> Sean Reifschneider <jafo(at)tummy(dot)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(at)Yahoo(dot)com #

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Peter Eisentraut 2003-04-14 16:38:16 Re: Docs patch to note that rules only get run once per query.
Previous Message Tom Lane 2003-04-14 04:11:55 Re: Docs patch to note that rules only get run once per query.