> **Function Scan** > <table> > <tr> > <td width="25%"><img src="assets/ex_functionscan.png"></td> > <td>A scan node that executes a set-returning function. The engine materializes the entire result set of the function before scanning it, which can be a memory bottleneck if the function returns a massive volume of data.</td> > </tr> > </table> > > ```sql > -- Scanning the output of generate_series > EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE) > SELECT * FROM generate_series(1,5); > ``` > > ![FunctionScan Plan Tree](assets/plan_tree_op_function_scan.svg) > > <!-- literal-explain-plan > Captured EXPLAIN provenance for the adjacent reader-facing visual plan. > Canonical capture metadata lives in scratch/actual_operation_plans.json. > > Function Scan on pg_catalog.generate_series (cost=0.00..0.05 rows=5 width=4) (actual time=0.004..0.004 rows=5 loops=1) > Output: generate_series > Function Call: generate_series(1, 5) > Planning Time: 0.032 ms > Execution Time: 0.018 ms > --> > > > <!-- > Raw-capture provenance — separate run. > SQL, setup, dataset, settings, and scope: artifacts/chapter4_capture_matrix.json. > Target: PostgreSQL 18.x companion fixture. Cache state: uncontrolled. > Boundary: pg_wait_tracer backend execution root; client states are included when the chart shows them. > Fidelity: exact pg_wait_tracer export. Not the adjacent EXPLAIN run; compare state shape, not durations. > --> > > ![Function Scan separate raw capture](assets/trace_op_function_scan.svg) > > <table> > <tr> > <td rowspan="2" width="25%"><img src="assets/ex_result.svg"></td> > <td><b>Performance</b></td><td>High performance for simple built-ins; performance is entirely dependent on the execution time of the underlying function.</td> > </tr> > <tr><td><b>Cost</b></td><td><code>function cost + cpu_tuple_cost * number of tuples</code></td></tr> > </table>