{"Entry":{"collection":"plan","key":"cte-scan","name":"CTE Scan","aliases":["CTE Scan","CteScan","T_CteScan"],"metadata":{"aliases":["CTE Scan","CteScan","T_CteScan"],"category":"Scan","content_hash":"23eb8e1e062f21a4a628d2b82bf42c5a0ee0846e090087982bd49f1ee26ff49c","imported_at":"2026-09-30T00:40:44.211622+08:00","name":"CTE Scan","name_zh":"CteScan","slug":"cte-scan","summary":"Reads the shared tuplestore of a common-table-expression plan, asking that plan for more rows when needed."}},"Definition":{"Collection":"plan","Key":"cte-scan","SourceDatabase":"center","Version":"18","SourceTable":"plan_node","SourceKey":"cte-scan","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"comparison_data":{"initializer":"ExecInitCteScan","memory_mechanism":"tuplestore","node_tag":"T_CteScan","parallel_callbacks":[],"partial_modes":[],"strategies":[],"text_names":["CTE Scan"]},"comparison_hash":"b99869b4fa614eb4c00675da9cf14c4d017018c55dbc2f0ea18d335cccb0a3aa","description":["Reads the shared tuplestore of a common-table-expression plan, asking that plan for more rows when needed."],"evidence_kind":"source and documentation","explain_names":["CTE Scan"],"explain_prefixes":["Parallel","Async"],"facts":[{"label":"Core node tag","value":"T_CteScan"},{"label":"Structured EXPLAIN Node Type","value":"CTE Scan"},{"label":"Inputs","value":"A CTE plan and shared tuplestore"},{"label":"Output","value":"CTE result tuples"},{"label":"Executor initializer","value":"ExecInitCteScan"},{"label":"Memory mechanism","value":"tuplestore"}],"memory":{"description":"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.","evidence":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeCtescan.c","path":"src/backend/executor/nodeCtescan.c","sha256":"63062406215ef682db58a20cb932ef30b83a6dca24557b625cf199d429fc8140","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/utils/sort/tuplestore.c","path":"src/backend/utils/sort/tuplestore.c","sha256":"27a85416bafed557006c705ab5d0c5dce3d3c1702812bb54d136f2ac4c41055a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"mechanism":"tuplestore","source_notes":[]},"node_tag":"T_CteScan","parallel_callbacks":[],"partial_modes":[],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"work_mem","url":"/wiki/guc/work_mem/?v=18"}],"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"runtime_verified":false,"sections":[{"paragraphs":["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."],"title":"EXPLAIN names and attributes"},{"paragraphs":["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."],"title":"Memory and temporary storage"},{"paragraphs":["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."],"title":"Parallel execution and instrumentation"},{"paragraphs":["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."],"title":"Executor implementation notes"},{"code":"case T_CteScan:\n\t\t\tpname = sname = \"CTE Scan\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"source_inventory":{"executor":"src/backend/executor/execProcnode.c","explain":"src/backend/commands/explain.c","implementation":"src/backend/executor/nodeCtescan.c"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1474","line":1474,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:269","line":269,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeCtescan.c","path":"src/backend/executor/nodeCtescan.c","sha256":"63062406215ef682db58a20cb932ef30b83a6dca24557b625cf199d429fc8140","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/utils/sort/tuplestore.c","path":"src/backend/utils/sort/tuplestore.c","sha256":"27a85416bafed557006c705ab5d0c5dce3d3c1702812bb54d136f2ac4c41055a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"strategies":[],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"CTE Scan","label":"CTE Scan"}],"title":"EXPLAIN labels in this source build"}]},"ManualEvidence":{"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1474","line":1474,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:269","line":269,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeCtescan.c","path":"src/backend/executor/nodeCtescan.c","sha256":"63062406215ef682db58a20cb932ef30b83a6dca24557b625cf199d429fc8140","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/utils/sort/tuplestore.c","path":"src/backend/utils/sort/tuplestore.c","sha256":"27a85416bafed557006c705ab5d0c5dce3d3c1702812bb54d136f2ac4c41055a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"MeasuredEvidence":{"runtime_verified":false}},"Text":{"Collection":"plan","Key":"cte-scan","SourceDatabase":"center","Version":"18","Locale":"en","Title":"CTE Scan","Summary":"Reads the shared tuplestore of a common-table-expression plan, asking that plan for more rows when needed.","BodyHTML":"\u003cp\u003eReads the shared tuplestore of a common-table-expression plan, asking that plan for more rows when needed.\u003c/p\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"17ab20eebde6d3895ce81c03370794281b92e3708ac613d1dda5f525c34f80aa","Payload":{"description":["Reads the shared tuplestore of a common-table-expression plan, asking that plan for more rows when needed."],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"},{"label":"work_mem","url":"/wiki/guc/work_mem/?v=18"}],"sections":[{"paragraphs":["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."],"title":"EXPLAIN names and attributes"},{"paragraphs":["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."],"title":"Memory and temporary storage"},{"paragraphs":["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."],"title":"Parallel execution and instrumentation"},{"paragraphs":["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."],"title":"Executor implementation notes"},{"code":"case T_CteScan:\n\t\t\tpname = sname = \"CTE Scan\";\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"CTE Scan","label":"CTE Scan"}],"title":"EXPLAIN labels in this source build"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
