Re: BUG #16978: Nested CTEs give ERROR in v13

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: tharakan(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16978: Nested CTEs give ERROR in v13
Date: 2021-04-23 18:03:22
Message-ID: 20210423180322.GD7629@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Apr 23, 2021 at 11:37:35AM -0400, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > On Fri, Apr 23, 2021 at 10:08:06AM -0400, Tom Lane wrote:
> >> FWIW, I don't see any error from this, either in HEAD or the
> >> back branches.
>
> > Uh, I don't see the failure in 13 head or master, but I do see it from a
> > 13.2 tree checkout. I will try to find the post-13.2 commit cause.
>
> Oh!
>
> [ checks commit log ]
>
> I bet it's 80ca8464f.

Confirmed. The bug was added by this commit in July 2019:

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1cff1b95a

and was included in PG 13. It was fixed by this post-PG 13.2 commit on
February 26, 2021:

https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=80ca8464f

The commit message is very clear:

makeDependencyGraphWalker and checkWellFormedRecursionWalker
thought they could hold onto a pointer to a list's first
cons cell while the list was modified by recursive calls.
That was okay when the cons cell was actually separately
--> palloc'd ... but since commit 1cff1b95a, it's quite unsafe,
leading to core dumps or incorrect complaints of faulty
WITH nesting.

--> In the field this'd require at least a seven-deep WITH nest
to cause an issue, but enabling DEBUG_LIST_MEMORY_USAGE
allows the bug to be seen with lesser nesting depths.

Per bug #16801 from Alexander Lakhin. Back-patch to v13.

It mentions the commit it fixed, and the fact that "this'd require at
least a seven-deep WITH nest to cause an issue", which is exactly what
you saw. :-)

I am attaching this later patch in a version that will cleanly apply to
PG 13.2, in case you need it. If not, the fix will appear in 13.3 which
will be released on May 13, 2021.

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

If only the physical world exists, free will is an illusion.

Attachment Content-Type Size
cte-13.2.diff text/x-diff 4.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2021-04-24 05:59:06 Re: BUG #16980: invalid memory alloc request size
Previous Message Tom Lane 2021-04-23 15:37:35 Re: BUG #16978: Nested CTEs give ERROR in v13