pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix incautious CTE matching in rewriteSearchAndCycle().
Date: Sat, 23 Apr 2022 16:16:18 +0000
Message-ID: <E1niIQk-000lSn-97@gemulon.postgresql.org> (raw)

Fix incautious CTE matching in rewriteSearchAndCycle().

This function looks for a reference to the recursive WITH CTE,
but it checked only the CTE name not ctelevelsup, so that it could
seize on a lower CTE that happened to have the same name.  This
would result in planner failures later, either weird errors such as
"could not find attribute 2 in subquery targetlist", or crashes
or assertion failures.  The code also merely Assert'ed that it found
a matching entry, which is not guaranteed at all by the parser.

Per bugs #17320 and #17318 from Zhiyong Wu.
Thanks to Kyotaro Horiguchi for investigation.

Discussion: https://postgr.es/m/17320-70e37868182512ab@postgresql.org
Discussion: https://postgr.es/m/17318-2eb65a3a611d2368@postgresql.org

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/dff6c77faf0c6bcf1d407dc3ffef9e169166c714

Modified Files
--------------
src/backend/rewrite/rewriteSearchCycle.c | 19 ++++++++++++++++---
src/test/regress/expected/with.out       | 10 ++++++++++
src/test/regress/sql/with.sql            | 10 ++++++++++
3 files changed, 36 insertions(+), 3 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1niIQk-000lSn-97@gemulon.postgresql.org>
Permalink:  ../E1niIQk-000lSn-97@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1niIQk-000lSn-97@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix incautious CTE matching in rewriteSearchAndCycle().
  In-Reply-To: <E1niIQk-000lSn-97@gemulon.postgresql.org>
  References: <E1niIQk-000lSn-97@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox