pgsql: Ensure ExecutorCheckPerms_hook is called from RI fast path

From: Amit Langote <amitlan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Ensure ExecutorCheckPerms_hook is called from RI fast path
Date: 2026-09-24 10:32:46
Message-ID: E1x9gkw-0000000137A-2Fn1@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Ensure ExecutorCheckPerms_hook is called from RI fast path

The fast path's ri_CheckPermissions() called ExecCheckOneRelPerms()
directly, so ExecutorCheckPerms_hook never saw the referenced-table
access that the SPI path's query exposed to it via ExecutorStart().
Modules such as sepgsql that rely on this hook therefore lost control
over FK checks against referenced tables that go through the fast
path.

So, build a one-entry range table and permission-info list and call
ExecCheckPermissions(). The hook now sees the same relation and
requiredPerms as before, once per check that goes through the fast
path. This also drops the shortcut that skipped the column-level
check when table-level privileges sufficed, since the hook must run
regardless. While at it, drop the explicit frees in the old code,
because both callers run ri_CheckPermissions() in a per-tuple context
that is reset after each check, so they were redundant.

Reported-by: Noah Misch <noah(at)leadboat(dot)com>
Discussion: https://postgr.es/m/20260705210533.ee.noahmisch%40microsoft.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5aeb36f3273c768831284082f85b63066e84f16d

Modified Files
--------------
src/backend/utils/adt/ri_triggers.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Langote 2026-09-24 10:33:00 pgsql: Ensure ExecutorCheckPerms_hook is called from RI fast path
Previous Message Álvaro Herrera 2026-09-24 10:25:26 pgsql: Wait for transactions of an initial decoding snapshot to commit