Contents
When do functions need to be marked parallel unsafe?
Functions and aggregates must be marked PARALLEL UNSAFE if they write to the database, access sequences, change the transaction state even temporarily (e.g., a PL/pgSQL function which establishes an EXCEPTION block to catch errors), or make persistent changes to settings.
Which is a parallel safe operation in PostgreSQL?
A parallel safe operation is one which does not conflict with the use of parallel query. A parallel restricted operation is one which cannot be performed in a parallel worker, but which can be performed in the leader while parallel query is in use.
When to declare a function unsafe in PostgreSQL?
If in doubt, it is probably best to label functions as UNSAFE. If a function executed within a parallel worker acquires locks which are not held by the leader, for example by querying a table not referenced in the query, those locks will be released at worker exit, not end of transaction.
Can a Planner automatically determine if a function is parallel safe?
The planner cannot automatically determine whether a user-defined function or aggregate is parallel safe, parallel restricted, or parallel unsafe, because this would require predicting every operation which the function could possibly perform. In general, this is equivalent to the Halting Problem and therefore impossible.
What does parallel restricted mean in PostgreSQL?
A marking of PARALLEL RESTRICTED means that the function may be present in a parallel query, but only in the portion of that query that executes in the leader. Parallel workers can never be asked to execute PARALLEL RESTRICTED functions.
What does parallel safe mean in PostgreSQL planner?
Parallel Safety. The planner classifies operations involved in a query as either parallel safe, parallel restricted, or parallel unsafe. A parallel safe operation is one which does not conflict with the use of parallel query.
https://www.youtube.com/watch?v=wz_rPKfhyGI