Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs
Date: 2021-02-25 01:30:41
Message-ID: YDb9wdB1GUkr+NAD@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Feb 24, 2021 at 07:36:26PM -0500, Tom Lane wrote:
> Here's a patch that I think fixes it correctly, including a test
> case that doesn't work with your patch.

Yes, thanks. While looking at that this morning, I have been able to
get a crash with my previous patch once I used more nesting in those
CTEs and your test is much simpler. I also got a test case able to
break things the same way in checkWellFormedRecursionWalker():
WITH RECURSIVE outermost(x) AS (
SELECT 1
UNION (WITH innermost as (WITH innermost2 AS (SELECT 2) SELECT * FROM innermost2)
SELECT * FROM outermost
UNION SELECT * FROM innermost)
)
SELECT * FROM outermost ORDER BY 1;

Your patch does not have a test for that, but it fixes the list
handling. With more nested levels and some UNIONs, the patch I sent
previously would equally break, though I am not sure we need more than
what I am sending here. What do you think about this extra test?
--
Michael

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2021-02-25 02:13:46 Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs
Previous Message Ryan Vinzent 2021-02-25 00:39:00 Re: Bug: Cannot insert multiple records using DEFAULT keyword for generated column