pgsql: Fix "failed to find plan for subquery/CTE" errors in EXPLAIN.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix "failed to find plan for subquery/CTE" errors in EXPLAIN.
Date: 2024-08-09 15:22:05
Message-ID: E1scRRN-003Rb4-1a@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix "failed to find plan for subquery/CTE" errors in EXPLAIN.

To deparse a reference to a field of a RECORD-type output of a
subquery, EXPLAIN normally digs down into the subquery's plan to try
to discover exactly which anonymous RECORD type is meant. However,
this can fail if the subquery has been optimized out of the plan
altogether on the grounds that no rows could pass the WHERE quals,
which has been possible at least since 3fc6e2d7f. There isn't
anything remaining in the plan tree that would help us, so fall back
to printing the field name as "fN" for the N'th column of the record.
(This will actually be the right thing some of the time, since it
matches the column names we assign to RowExprs.)

In passing, fix a comment typo in create_projection_plan, which
I noticed while experimenting with an alternative fix for this.

Per bug #18576 from Vasya B. Back-patch to all supported branches.

Richard Guo and Tom Lane

Discussion: https://postgr.es/m/18576-9feac34e132fea9e@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3ad35d5022c9e5329906542150a19f9a38f9564d

Modified Files
--------------
src/backend/optimizer/plan/createplan.c | 2 +-
src/backend/utils/adt/ruleutils.c | 43 ++++++++++++++++++++------
src/test/regress/expected/rowtypes.out | 54 +++++++++++++++++++++++++++++++++
src/test/regress/sql/rowtypes.sql | 21 +++++++++++++
4 files changed, 109 insertions(+), 11 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2024-08-09 15:53:58 pgsql: doc: Fix name of CRC algorithm in "Reliability" section.
Previous Message Tom Lane 2024-08-09 15:22:04 pgsql: Fix "failed to find plan for subquery/CTE" errors in EXPLAIN.