Re: stable for each row before insert trigger

From: Luca Ferrari <fluca1978(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Олег Самойлов <splarv(at)ya(dot)ru>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: stable for each row before insert trigger
Date: 2019-10-18 08:09:12
Message-ID: CAKoxK+56R4KHM1sUhUbsH2=J3GTUn+HXD6gp9di_nD9UsRQM-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Oct 18, 2019 at 9:16 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> =?utf-8?B?0J7Qu9C10LMg0KHQsNC80L7QudC70L7Qsg==?= <splarv(at)ya(dot)ru> writes:
> > According to documentation the words "VOLATILE, STABLE, IMMUTABLE" is somehow useful with trigger functions, for instance mentioned that the AFTER INSERT trigger should be VOLATILE. The question is how this words affect a for each row before insert trigger? Can be some optimisation here?
>
> Where did you read that? There's no optimization that considers the
> volatility of trigger functions --- they'll be called exactly when
> specified, no more or less.

I suspect this sentence could have raised the OP doubt:

"For best optimization results, you should label your functions with
the strictest volatility category that is valid for them."

(from <https://www.postgresql.org/docs/11/xfunc-volatility.html>).

However, here <https://www.postgresql.org/docs/11/trigger-datachanges.html>
it is specified that:

"If your trigger function is written in any of the standard procedural
languages, then the above statements apply only if the function is
declared VOLATILE. Functions that are declared STABLE or IMMUTABLE
will not see changes made by the calling command in any case."

which I hope is the answer to the original question.

Luca

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Luca Ferrari 2019-10-18 08:12:02 Re: Postgres Point in time Recovery (PITR),
Previous Message Tom Lane 2019-10-18 07:15:58 Re: stable for each row before insert trigger