Trigger functions and parallelism

From: "Karl O(dot) Pinc" <kop(at)karlpinc(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Trigger functions and parallelism
Date: 2023-10-02 16:49:42
Message-ID: 20231002114942.56a6f656@slate.karlpinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

It's not entirely clear to me what the conditions
are for function parallel safety. While the documentation
seems pretty clear in most cases, there still some
verbiage that requires knowledge of internals
in order to be useful.

What I'm looking for is some general statements about
parallel safety for trigger functions. I don't know
enough about parallelism to even know if it applies
to data modification statements.

It seems to me that, because raising any sort of exception
affects transaction state, that triggers which
validate data integrity and raise errors must be PARALLEL UNSAFE.

But are any sort of AFTER INSERT trigger on a generated sequential key
parallel UNSAFE because they access sequence state via NEW?

Can something generic be said, like: "Most trigger functions should
be declared PARALLEL UNSAFE (the default) with the possible exception
of BEFORE triggers that raise no exceptions and control system
behavior by their return value."?

What can be said to provide some overview which gives
guidance on parallelism to trigger authors?

Regards,

Karl <kop(at)karlpinc(dot)com>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-10-02 17:07:19 Re: Trigger functions and parallelism
Previous Message byme 2023-10-02 16:19:40 pg_stat_statements IN problem