Pager usage is off. version -------------------------------------------------------------------- PostgreSQL 20devel on x86_64-linux, compiled by gcc-14.2.0, 64-bit (1 row) name | setting ---------------------+--------- enable_sort | on hash_mem_multiplier | 2 work_mem | 4096 (3 rows) psql:/repro/repro.sql:12: NOTICE: 00000: table "t0" does not exist, skipping LOCATION: DropErrorMsgNonExistent, tablecmds.c:1527 DROP TABLE CREATE TABLE == case 1: recursive UNION, inflated estimate (default settings) You are now connected to database "postgres" as user "postgres". SET psql:/repro/repro.sql:23: ERROR: 53200: out of memory DETAIL: Failed on request of size 68719476736 in memory context "ExecutorState". LOCATION: MemoryContextAllocationFailure, mcxt.c:1208 psql:/repro/repro.sql:27: ERROR: 53200: out of memory DETAIL: Failed on request of size 68719476736 in memory context "ExecutorState". LOCATION: MemoryContextAllocationFailure, mcxt.c:1208 peak_rss_mb ------------- 24 (1 row) == control 1: same query, UNION ALL (no hash table) You are now connected to database "postgres" as user "postgres". count ------- 0 (1 row) peak_rss_mb ------------- 21 (1 row) == case 2: recursive UNION, accurate estimate of 1M rows You are now connected to database "postgres" as user "postgres". count --------- 1000000 (1 row) peak_rss_mb ------------- 1094 (1 row) == control 2: same rows, UNION ALL You are now connected to database "postgres" as user "postgres". count --------- 1000000 (1 row) peak_rss_mb ------------- 33 (1 row) == case 3: hashed EXCEPT chosen while disabled (enable_sort = off) You are now connected to database "postgres" as user "postgres". SET SET psql:/repro/repro.sql:59: ERROR: 53200: out of memory DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState". LOCATION: MemoryContextAllocationFailure, mcxt.c:1208 psql:/repro/repro.sql:61: ERROR: 53200: out of memory DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState". LOCATION: MemoryContextAllocationFailure, mcxt.c:1208 peak_rss_mb ------------- 24 (1 row) == control 3: same query, default settings (sorted SetOp) You are now connected to database "postgres" as user "postgres". QUERY PLAN -------------------------------------------------------------------------------------------- SetOp Except (cost=15879164969983.26..16407700298108.28 rows=1600000000 width=16) -> Sort (cost=15879164969983.26..15984871235608.26 rows=42282506250000 width=16) Sort Key: a.c0, b.c0, c.c0, d.c0 -> Nested Loop (cost=0.00..528738676754.88 rows=42282506250000 width=16) -> Nested Loop (cost=0.00..207348588.00 rows=16581375000 width=12) -> Nested Loop (cost=0.00..81358.62 rows=6502500 width=8) -> Seq Scan on t0 a (cost=0.00..35.50 rows=2550 width=4) -> Materialize (cost=0.00..48.25 rows=2550 width=4) -> Seq Scan on t0 b (cost=0.00..35.50 rows=2550 width=4) -> Materialize (cost=0.00..48.25 rows=2550 width=4) -> Seq Scan on t0 c (cost=0.00..35.50 rows=2550 width=4) -> Materialize (cost=0.00..48.25 rows=2550 width=4) -> Seq Scan on t0 d (cost=0.00..35.50 rows=2550 width=4) -> Result (cost=0.00..0.01 rows=1 width=16) (14 rows) c0 | c0 | c0 | c0 ----+----+----+---- (0 rows) peak_rss_mb ------------- 22 (1 row) == case 4: hashed EXCEPT, default settings, hash-only type (xid) You are now connected to database "postgres" as user "postgres". psql:/repro/repro.sql:75: ERROR: 53200: out of memory DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState". LOCATION: MemoryContextAllocationFailure, mcxt.c:1208 psql:/repro/repro.sql:77: ERROR: 53200: out of memory DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState". LOCATION: MemoryContextAllocationFailure, mcxt.c:1208 peak_rss_mb ------------- 22 (1 row) == server log (errors and backtraces) 2026-10-15 13:51:49.035 UTC [42] ERROR: out of memory 2026-10-15 13:51:49.035 UTC [42] DETAIL: Failed on request of size 68719476736 in memory context "ExecutorState". postgres: postgres postgres [local] EXPLAIN(BuildTupleHashTable+0x164) [0x609aed0af5dd] postgres: postgres postgres [local] EXPLAIN(ExecInitRecursiveUnion+0x2c7) [0x609aed10b85d] 2026-10-15 13:51:49.038 UTC [42] ERROR: out of memory 2026-10-15 13:51:49.038 UTC [42] DETAIL: Failed on request of size 68719476736 in memory context "ExecutorState". postgres: postgres postgres [local] SELECT(BuildTupleHashTable+0x164) [0x609aed0af5dd] postgres: postgres postgres [local] SELECT(ExecInitRecursiveUnion+0x2c7) [0x609aed10b85d] 2026-10-15 13:51:51.715 UTC [46] ERROR: out of memory 2026-10-15 13:51:51.715 UTC [46] DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState". postgres: postgres postgres [local] EXPLAIN(BuildTupleHashTable+0x164) [0x609aed0af5dd] postgres: postgres postgres [local] EXPLAIN(ExecInitSetOp+0x314) [0x609aed10f598] 2026-10-15 13:51:51.718 UTC [46] ERROR: out of memory 2026-10-15 13:51:51.718 UTC [46] DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState". postgres: postgres postgres [local] SELECT(BuildTupleHashTable+0x164) [0x609aed0af5dd] postgres: postgres postgres [local] SELECT(ExecInitSetOp+0x314) [0x609aed10f598] 2026-10-15 13:51:51.729 UTC [48] ERROR: out of memory 2026-10-15 13:51:51.729 UTC [48] DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState". 2026-10-15 13:51:51.731 UTC [48] ERROR: out of memory 2026-10-15 13:51:51.731 UTC [48] DETAIL: Failed on request of size 34359738368 in memory context "ExecutorState".