Gregory Arenius
Gregory Arenius

Reputation: 3214

Why are scans of CTEs and temporary tablest parallel restricted?

From the PostgreSQL manual:

The following operations are always parallel restricted:

  • Scans of common table expressions (CTEs).

  • Scans of temporary tables.

Why are parallel scans of CTEs and temporary tables restricted?

Upvotes: 1

Views: 479

Answers (2)

jjanes
jjanes

Reputation: 44305

Note that CTE scans are only a barrier if they still exist after planning. If the CTE syntax was "inlined" during planning, it is not a barrier to parallel. I wonder if the docs should be changed to clarify that?

Upvotes: 3

saurabh bhadane
saurabh bhadane

Reputation: 211

Parallel restricted

Scans on CTE & Temp tables:

The reason is that both CTEs and temporary tables are private to the backend process that created them, and parallel worker processes are different processes that do not have access to the private resources of the leader process.

To make CTE scans parallel safe, CTEs would have to be materialized in shared memory.

https://stackoverflow.com/a/58445299/11094058

Upvotes: 3

Related Questions