The following operations are always parallel restricted.
- Scans of common table expressions (CTEs).
- Scans of temporary tables.
Further down on the same manual page:
[...] Similarly, functions must be marked
PARALLEL RESTRICTEDif they access temporary tables, client connection state, cursors, prepared statements, or miscellaneous backend-local state which the system cannot synchronize across workers. For example,
randomare parallel restricted for this last reason.
No mention of CTEs. Now I am unsure whether I can use
PARALLEL SAFE for functions containing a CTE. It would make sense to me for those to be only
Context: I have to determine the best label for existing user-defined functions. The setting is new since Postgres 9.6, and can have a massive impact on performance as operations involving functions that are not
PARALLEL SAFE will not be performed by parallel workers,
PARALLEL RESTRICTED only by the leader. (And
PARALLEL USAFE disables parallelism altogether.)
I posted a related question on pgsql-general.