↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Plan Nodes / Combination

Recursive Union

RecursiveUnion

Executes the non-recursive and recursive terms of a recursive union using working and intermediate tables.

Reading PostgreSQL 18.6.

Description

Executes the non-recursive and recursive terms of a recursive union using working and intermediate tables.

Core node tag
T_RecursiveUnion
Structured EXPLAIN Node Type
Recursive Union
Inputs
Non-recursive and recursive child plans
Output
Recursive query tuples
Executor initializer
ExecInitRecursiveUnion
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: Recursive Union.

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

nodeRecursiveunion.c routines to handle RecursiveUnion nodes.

To implement UNION (without ALL), we need a hashtable that stores tuples already seen. The hash key is computed from the grouping columns.

If both child plans deliver the same fixed tuple slot type, we can tell BuildTupleHashTable to expect that slot type as input. Otherwise, we'll pass NULL denoting that any slot type is possible.

Scans the recursive query sequentially and returns the next qualifying tuple.

2.1 WT := RT 2.2 while WT is not empty repeat 2.3 to 2.6. if WT is empty returns RT 2.3 replace the name of recursive term with WT 2.4 evaluate the recursive term and store into WT 2.5 append WT to RT 2.6 go back to 2.2

EXPLAIN identity in core source

case T_RecursiveUnion:
			pname = sname = "Recursive Union";
			break;

EXPLAIN labels in this source build

Text-format labelStructured node identity
Recursive UnionRecursive Union

Related entries

Documentation and source

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

Export JSON · Back to Plan Nodes · Recorded in PostgreSQL 10 through 20; the first sample is not necessarily its introduction.