Re: Rules: A Modest Proposal

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: josh(at)agliodbs(dot)com (Josh Berkus), pgsql-hackers(at)postgresql(dot)org
Subject: Re: Rules: A Modest Proposal
Date: 2009-10-06 01:56:07
Message-ID: 873a5xl1zc.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Josh" == Josh Berkus <josh(at)agliodbs(dot)com> writes:

>> 1) any reference in an insert rule to NEW.col where col has a volatile
>> default, or the expression in the insert statement was volatile, or
>> the expression's value is changed by the insert, will do the wrong
>> thing:

Josh> Is this different from triggers?

Absolutely. In an AFTER trigger, the trigger's NEW variable is guaranteed
to be exactly the inserted values.

So doing a log table with triggers is reliable, whereas doing it with rules
is not.

>> 2) any rule with multiple actions, each action is affected by the
>> results of the previous ones. A classic example of this is in the
>> use of OLD in delete or update rules; OLD _does not return a row_
>> if a previous action in the rule deleted the row or updated it so
>> that it no longer matches.

Josh> I know this is not any different from triggers which cascade.

Of course it is different. A trigger's value of OLD is always the
actual content of the previous row version, it doesn't magically
disappear the way that rule OLD does.

Josh> David's basic proposal, as I understand, is to remove RULEs and
Josh> replace them with triggers on views. However, there are *lots*
Josh> of ways to screw yourself up with triggers as well.

There is simply no comparison here. Triggers are simple procedural logic
which any novice can use effectively with little chance of falling into
any major pitfalls; rules are a bizarre macro-language which even experts
have a hard time using correctly.

Josh> For example see my previously reported bug about referential
Josh> integrity and self-triggers.

link?

Josh> Triggers also have potential security issues which rules lack.

Example?

Josh> I happen to like having RULEs in my arsenal of tricks for
Josh> getting the database to do Nifty Stuff. I've always considered
Josh> them advanced database programming, and not for beginners.

The difference is that rules aren't for advanced users either (as
you've just demonstrated by not understanding the differences in
behaviour between rules and triggers).

--
Andrew (irc:RhodiumToad)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message KaiGai Kohei 2009-10-06 02:15:57 Re: [PATCH] Largeobject access controls
Previous Message Robert Haas 2009-10-06 01:34:36 CommitFest 2009-09: how do we close this one out?