> **Table Function Scan** > <table> > <tr> > <td width="25%"><img src="assets/ex_tablefuncscan.png"></td> > <td>Executes functions that return a set of rows (e.g., <code>xmltable</code> or <code>jsonb_to_recordset</code>). The engine calls the function and then treats its output as a virtual table that can be scanned, filtered, or joined like any other relation.</td> > </tr> > </table> > > ```sql > -- Querying a generated XML table > EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE) > SELECT * FROM xmltable('/root/item' > PASSING '<root><item>1</item><item>2</item></root>' > COLUMNS i int PATH '.'); > ``` > > ![TableFuncScan Plan Tree](assets/plan_tree_op_table_func_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. > > Table Function Scan on "xmltable" (cost=0.00..1.00 rows=100 width=4) (actual time=0.030..0.030 rows=2 loops=1) > Output: i > Table Function Call: XMLTABLE(('/root/item'::text) PASSING ('<root><item>1</item><item>2</item></root>'::xml) COLUMNS i integer PATH ('.'::text)) > Planning Time: 0.030 ms > Execution Time: 0.045 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. > --> > > ![Table Function Scan separate raw capture](assets/trace_op_table_func_scan.svg) > > <table> > <tr> > <td rowspan="2" width="25%"><img src="assets/ex_table_func_scan.svg"></td> > <td><b>Performance</b></td><td>Depends on the complexity and volume of the generated table.</td> > </tr> > <tr><td><b>Cost</b></td><td><code>function cost + cpu_tuple_cost * number of rows</code></td></tr> > </table>