BUG #19063: Heavily nesting trivial ROW projections produces out of memory error

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: lukas(dot)eder(at)gmail(dot)com
Subject: BUG #19063: Heavily nesting trivial ROW projections produces out of memory error
Date: 2025-09-24 14:06:07
Message-ID: 19063-c1ba39b11b9d43b7@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19063
Logged by: Lukas Eder
Email address: lukas(dot)eder(at)gmail(dot)com
PostgreSQL version: 18rc1
Operating system: Linux in Docker in Windows
Description:

Try this query:

select
row (row (row (row (row (row (row (row (
row (row (row (row (row (row (row (row (
row (row (row (row (row (row (row (row (
row (row (row (row (row (row (row (row (
1
))))))))
))))))))
))))))))
)))))))) as "nested";

It produces the following error:

SQL Error [54000]: ERROR: string buffer exceeds maximum allowed length
(1073741823 bytes)
Detail: Cannot enlarge string buffer containing 1073741822 bytes by 1 more
bytes.

I don't understand how such excessive memory consumption is produced by such
a "simple" query. The nesting is a bit excessive, sure, but I think there's
a deeper underlying inefficiency that might be worth addressing.

I've tried both these versions:

- PostgreSQL 17.5 (Debian 17.5-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled
by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
- PostgreSQL 18rc1 (Debian 18~rc1-1.pgdg13+1) on x86_64-pc-linux-gnu,
compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-09-24 14:41:24 Re: BUG #19062: PostgreSQL 12.22 does not compile because of conflicting types for CollationCreate
Previous Message Wei Sun 2025-09-24 11:27:11 回复: The issue of incorrect width estimation in UNION queries