Home > Software engineering >  Why are scans of CTEs and temporary tablest parallel restricted?
Why are scans of CTEs and temporary tablest parallel restricted?

Time:10-12

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?

CodePudding user response:

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

CodePudding user response:

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?

  • Related