Re: Rule vs Trigger - Mailing list pgsql-general

From Albe Laurenz
Subject Re: Rule vs Trigger
Date
Msg-id AFCCBB403D7E7A4581E48F20AF3E5DB2038C4AD7@EXADV1.host.magwien.gv.at
Whole thread Raw
In response to Re: Rule vs Trigger  (Richard Broersma Jr <rabroersma@yahoo.com>)
Responses Re: Rule vs Trigger  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Richard Broersma Jr wrote:
> --- Alfred Zhao <rongkai.zhao@gmail.com> wrote:
>> Suppose I want to update a statistics table S after an
>> insertion into an activity table A. In order to update S
>> automatically, I can either create a rule on A or create
>> an after trigger on A. What's the performance implication
>> on using rule vs trigger? Thanks in advance.
>
> My understanding is that Triggers offer better performance
> than rules do.

A trigger FOR EACH STATEMENT will execute the trigger function
for each row affacted by the statement. A rule would only
execute one additional statement. So if you can do it with a rule
conveniently, the rule will probably be faster.

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: "Albe Laurenz"
Date:
Subject: Re: postgresql varchar[] data type equivalent in Oracle
Next
From: Rafal Pietrak
Date:
Subject: Re: a JOIN on same table, but 'slided over'