pgsql: Fix mishandling of OLD/NEW references in subqueries in rule acti

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix mishandling of OLD/NEW references in subqueries in rule acti
Date: 2023-02-25 14:51:12
Message-ID: E1pVvtH-000ey5-Tv@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix mishandling of OLD/NEW references in subqueries in rule actions.

If a rule action contains a subquery that refers to columns from OLD
or NEW, then those are really lateral references, and the planner will
complain if it sees such things in a subquery that isn't marked as
lateral. However, at rule-definition time, the user isn't required to
mark the subquery with LATERAL, and so it can fail when the rule is
used.

Fix this by marking such subqueries as lateral in the rewriter, at the
point where they're used.

Dean Rasheed and Tom Lane, per report from Alexander Lakhin.
Back-patch to all supported branches.

Discussion: https://postgr.es/m/5e09da43-aaba-7ea7-0a51-a2eb981b058b%40gmail.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/79f194cc0144fad07fa18c4b2a5f32bce9035ee0

Modified Files
--------------
src/backend/rewrite/rewriteHandler.c | 23 +++++++++++++++++++----
src/test/regress/expected/rules.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/rules.sql | 17 +++++++++++++++++
3 files changed, 61 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2023-02-25 19:44:40 pgsql: Fix MULTIEXPR_SUBLINK with partitioned target tables, yet again.
Previous Message Jeff Davis 2023-02-24 17:30:00 pgsql: Silence compiler warnings introduced by d87d548cd0.