pgsql: postgres_fdw: Avoid 'variable not found in subplan target list'

From: Etsuro Fujita <efujita(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: postgres_fdw: Avoid 'variable not found in subplan target list'
Date: 2022-09-14 09:54:39
Message-ID: E1oYP6M-000Hxk-Ky@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

postgres_fdw: Avoid 'variable not found in subplan target list' error.

The tlist of the EvalPlanQual outer plan for a ForeignScan node is
adjusted to produce a tuple whose descriptor matches the scan tuple slot
for the ForeignScan node. But in the case where the outer plan contains
an extra Sort node, if the new tlist contained columns required only for
evaluating PlaceHolderVars or columns required only for evaluating local
conditions, this would cause setrefs.c to fail with the error.

The cause of this is that when creating the outer plan by injecting the
Sort node into an alternative local join plan that could emit such extra
columns as well, we fail to arrange for the outer plan to propagate them
up through the Sort node, causing setrefs.c to fail to match up them in
the new tlist to what is available from the outer plan. Repair.

Per report from Alexander Pyhalov.

Richard Guo and Etsuro Fujita, reviewed by Alexander Pyhalov and Tom Lane.
Backpatch to all supported versions.

Discussion: http://postgr.es/m/cfb17bf6dfdf876467bd5ef533852d18%40postgrespro.ru

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6749d4e8c71bac9cd06f9c923d38e34d07211f15

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 79 ++++++++++++++++++++++++++
contrib/postgres_fdw/postgres_fdw.c | 49 ++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql | 13 +++++
3 files changed, 141 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2022-09-14 13:55:20 pgsql: Remove duplicate initialization
Previous Message Alvaro Herrera 2022-09-14 09:40:09 Re: pgsql: Doc: Explain about Column List feature.