Re: ERROR: stack depth limit exceeded - Mailing list pgsql-general

From Tom Lane
Subject Re: ERROR: stack depth limit exceeded
Date
Msg-id 1871319.1694181213@sss.pgh.pa.us
Whole thread Raw
In response to Re: ERROR: stack depth limit exceeded  (gzh <gzhcoder@126.com>)
Responses Re: ERROR: stack depth limit exceeded
List pgsql-general
gzh  <gzhcoder@126.com> writes:
> In the Release Notes for PostgreSQL 12.14, we saw the following change:
> https://www.postgresql.org/docs/release/12.14/

>> Add recursion and looping defenses in subquery pullup (Tom Lane)
>> A contrived query can result in deep recursion and unreasonable amounts of time spent trying to flatten subqueries.
Aproper fix for that seems unduly invasive for a back-patch, but we can at least add stack depth checks and an
interruptcheck to allow the query to be cancelled. 


> Our understanding is that this change will cause some complex SQL statements
> that were previously not reporting errors to report errors in the new version.

The key word there is "contrived".  You are not going to hit this limit
without intentionally trying.  The example that led to adding this check
was a synthetic query with 10000 UNION ALL branches:

https://www.postgresql.org/message-id/flat/703c09a2-08f3-d2ec-b33d-dbecd62428b8%40postgrespro.ru

Also notice that the query misbehaved before this patch, too, by consuming
excessive RAM.

            regards, tom lane



pgsql-general by date:

Previous
From: Nature Conservation Geovista Space
Date:
Subject: Even if I have a lot of free space PgSQL returns "ERROR: could not extend file - No space left on device"
Next
From: Adrian Klaver
Date:
Subject: Re: Even if I have a lot of free space PgSQL returns "ERROR: could not extend file - No space left on device"