Can functions containing a CTE be PARALLEL SAFE?

From: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Can functions containing a CTE be PARALLEL SAFE?
Date: 2019-10-17 03:09:17
Message-ID: CAGHENJ6jnwGBn5UG3ZjsTkOtvt1nRKuapcL9wx0Qx0H=HVvqxQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

[The manual for Postgres 12 says][1]:

> The following operations are always parallel restricted.

> - Scans of common table expressions (CTEs).
> - Scans of temporary tables.
> - ...

Further down on the same [manual page:][2]

> [...] Similarly, functions must be marked PARALLEL RESTRICTED if they
access
> temporary tables, client connection state, cursors, prepared
> statements, or miscellaneous backend-local state which the system
> cannot synchronize across workers. For example, setseed and random are
> parallel restricted for this last reason.

No mention of CTEs.

I searched the list archives and found a statement from Thomas Munro
[here][3]:

> That means that these CTEs can only be scanned in the leader process.

Now I am unsure whether I can use `PARALLEL SAFE` for functions containing
a CTE (while fulfilling all other criteria)?

Would the new inlining of CTEs in Postgres 12 have any role in this?

I posted a [similar question on dba.SE][4].

Regards
Erwin Brandstetter

[1]: https://www.postgresql.org/docs/12/parallel-safety.html
[2]:
https://www.postgresql.org/docs/12/parallel-safety.html#PARALLEL-LABELING
[3]:
https://www.postgresql.org/message-id/CAEepm=03s4Yih+c0pCTfKi0O8zgq-P4VfCVEk5VVXcR6aXHm4A@mail.gmail.com
[4]: https://dba.stackexchange.com/q/251274/3684

That means that these CTEs can only be scanned in the
leader process.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Luca Ferrari 2019-10-17 06:51:42 Re: PostgreSQL memory usage
Previous Message Adrian Klaver 2019-10-16 22:31:38 Re: CVE-2018-1058