Wiki / Plan Nodes / Scan
CTE Scan
CteScan
Reads the shared tuplestore of a common-table-expression plan, asking that plan for more rows when needed.
Reading PostgreSQL 18.6.
Description
Reads the shared tuplestore of a common-table-expression plan, asking that plan for more rows when needed.
- Core node tag
- T_CteScan
- Structured EXPLAIN Node Type
- CTE Scan
- Inputs
- A CTE plan and shared tuplestore
- Output
- CTE result tuples
- Executor initializer
- ExecInitCteScan
- Memory mechanism
- tuplestore
EXPLAIN names and attributes
Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.
Text names recorded by this source: CTE Scan.
Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node.
Memory and temporary storage
This node creates a tuplestore with work_mem. The tuplestore can move stored tuples to temporary files; this does not make work_mem a cap on every allocation made by the node.
Parallel execution and instrumentation
The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.
Callbacks in this build: none extracted from this node implementation.
Executor implementation notes
If we are not at the end of the tuplestore, or are going backwards, try to fetch a tuple from tuplestore.
When reversing direction at tuplestore EOF, the first gettupleslot call will fetch the last-added tuple; but we want to return the one before that, if possible. So do an extra fetch.
If we can fetch another tuple from the tuplestore, return it.
Note: we have to use copy=true in the tuplestore_gettupleslot call, because we are sharing the tuplestore with other nodes that might write into the tuplestore before we get called again.
Note: the eof_cte state variable exists to short-circuit further calls of the CTE plan. It's not optional, unfortunately, because some plan node types are not robust about being called again when they've already returned NULL.
EXPLAIN identity in core source
case T_CteScan:
pname = sname = "CTE Scan";
break;EXPLAIN labels in this source build
| Text-format label | Structured node identity |
|---|---|
| CTE Scan | CTE Scan |
Related entries
Documentation and source
- src/backend/commands/explain.c:1474
- src/backend/executor/execProcnode.c:269
- src/backend/executor/nodeCtescan.c
- src/include/nodes/plannodes.h
- src/backend/utils/sort/tuplestore.c
Source build
- Version
- 18.6
- Build
- PostgreSQL 18.6 source archive
- Source fingerprint
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f
Compare versions
PostgreSQL 17 → 18: unchanged.
Compares recorded interfaces and attributes. Source fingerprints and build metadata are excluded; an absent sample is not proof of the introduction or removal release.
Related entries
Bitmap Heap ScanBitmapHeapScanFunction ScanFunctionScanIndex Only ScanIndexOnlyScanIndex ScanIndexScanNamed Tuplestore ScanNamedTuplestoreScanSample ScanSampleScanSeq ScanSeqScanSubquery ScanSubqueryScanTable Function ScanTableFuncScanTid Range ScanTidRangeScanTid ScanTidScanValues ScanValuesScan
Export JSON · Back to Plan Nodes · Recorded in PostgreSQL 10 through 20; the first sample is not necessarily its introduction.