Search code examples
postgresqlparallel-processingcommon-table-expressionpostgresql-14

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?


Solution

  • 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