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: Remove inadequate assertion check in CTE inlining.
Date: Thu, 21 Apr 2022 21:59:04 +0000
Message-ID: <E1nhepM-000UTe-FR@gemulon.postgresql.org> (raw)

Remove inadequate assertion check in CTE inlining.

inline_cte() expected to find exactly as many references to the
target CTE as its cterefcount indicates.  While that should be
accurate for the tree as emitted by the parser, there are some
optimizations that occur upstream of here that could falsify it,
notably removal of unused subquery output expressions.

Trying to make the accounting 100% accurate seems expensive and
doomed to future breakage.  It's not really worth it, because
all this code is protecting is downstream assumptions that every
referenced CTE has a plan.  Let's convert those assertions to
regular test-and-elog just in case there's some actual problem,
and then drop the failing assertion.

Per report from Tomas Vondra (thanks also to Richard Guo for
analysis).  Back-patch to v12 where the faulty code came in.

Discussion: https://postgr.es/m/29196a1e-ed47-c7ca-9be2-b1c636816183@enterprisedb.com

Branch
------
REL_13_STABLE

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

Modified Files
--------------
src/backend/optimizer/path/allpaths.c   |  3 +-
src/backend/optimizer/plan/createplan.c |  3 +-
src/backend/optimizer/plan/subselect.c  |  8 -----
src/include/nodes/pathnodes.h           |  3 +-
src/test/regress/expected/with.out      | 64 +++++++++++++++++++++++++++++++++
src/test/regress/sql/with.sql           | 31 ++++++++++++++++
6 files changed, 101 insertions(+), 11 deletions(-)



view thread (4+ messages)  latest in thread

Message-ID: <E1nhepM-000UTe-FR@gemulon.postgresql.org>
Permalink:  ../E1nhepM-000UTe-FR@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nhepM-000UTe-FR@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: Remove inadequate assertion check in CTE inlining.
  In-Reply-To: <E1nhepM-000UTe-FR@gemulon.postgresql.org>
  References: <E1nhepM-000UTe-FR@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