public inbox for [email protected]  
help / color / mirror / Atom feed
From: Jan Wieck <[email protected]>
To: Tom Lane <[email protected]>
Cc: Sean Reifschneider <[email protected]>
Cc: [email protected]
Subject: Re: Docs patch to note that rules only get run once per query.
Date: Mon, 14 Apr 2003 07:21:01 -0400
Message-ID: <[email protected]> (raw)
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

Tom Lane wrote:
> 
> Sean Reifschneider <[email protected]> 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.                                  #
#================================================== [email protected] #




view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Docs patch to note that rules only get run once per query.
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox