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

Поиск
Список
Период
Сортировка
От Jan Wieck
Тема Re: Docs patch to note that rules only get run once per query.
Дата
Msg-id 3E9A999D.82FA4835@Yahoo.com
обсуждение исходный текст
Ответ на Docs patch to note that rules only get run once per query.  (Sean Reifschneider <jafo@tummy.com>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Docs patch to note that rules only get run once per query.
Следующее
От: Curt Sampson
Дата:
Сообщение: Re: 6.8.5: Location of CURRENT_DATE unclear