Re: Rules: A Modest Proposal

Поиск
Список
Период
Сортировка
От Andrew Gierth
Тема Re: Rules: A Modest Proposal
Дата
Msg-id 873a5xl1zc.fsf@news-spur.riddles.org.uk
обсуждение исходный текст
Ответ на Re: Rules: A Modest Proposal  (Josh Berkus <josh@agliodbs.com>)
Список pgsql-hackers
>>>>> "Josh" == Josh Berkus <josh@agliodbs.com> writes:
>> 1) any reference in an insert rule to NEW.col where col has a volatile>> default, or the expression in the insert
statementwas 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
ofthis is in the>> use of OLD in delete or update rules; OLD _does not return a row_>> if a previous action in the rule
deletedthe 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 andJosh> 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 referentialJosh> 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 forJosh> getting the database to do Nifty Stuff.  I've
alwaysconsideredJosh> 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)


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: CommitFest 2009-09: how do we close this one out?
Следующее
От: KaiGai Kohei
Дата:
Сообщение: Re: [PATCH] Largeobject access controls