> **Recursive Union**
> <table>
> <tr>
> <td width="25%"><img src="assets/ex_recursiveunion.png"></td>
> <td>Orchestrates the execution of recursive Common Table Expressions.</td>
> </tr>
> </table>
>
> ```sql
> -- Generating a sequence using a recursive CTE
> EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE)
> WITH RECURSIVE t(n) AS (
> VALUES (1)
> UNION ALL
> SELECT n+1 FROM t WHERE n < 10
> ) SELECT * FROM t;
> ```
>
> 
>
> <!-- literal-explain-plan
> Captured EXPLAIN provenance for the adjacent reader-facing visual plan.
> Canonical capture metadata lives in scratch/actual_operation_plans.json.
>
> CTE Scan on t (cost=2.65..3.27 rows=31 width=4) (actual time=0.002..0.006 rows=10 loops=1)
> Output: t.n
> CTE t
> -> Recursive Union (cost=0.00..2.65 rows=31 width=4) (actual time=0.001..0.004 rows=10 loops=1)
> -> Result (cost=0.00..0.01 rows=1 width=4) (actual time=0.001..0.001 rows=1 loops=1)
> Output: 1
> -> WorkTable Scan on t t_1 (cost=0.00..0.23 rows=3 width=4) (actual time=0.000..0.000 rows=1 loops=10)
> Output: (t_1.n + 1)
> Filter: (t_1.n < 10)
> Rows Removed by Filter: 0
> Planning Time: 0.052 ms
> Execution Time: 0.024 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>
> <tr>
> <td rowspan="2" width="25%"><img src="assets/ex_recursive_union.svg"></td>
> <td><b>Performance</b></td><td>Efficiency depends on the recursion depth and the size of the "WorkTable" (the intermediate result set).</td>
> </tr>
> <tr><td><b>Cost</b></td><td><code>iteration cost * number of iterations</code></td></tr>
> </table>