pgsql: Begin RI fast-path index scan under the switched user id

From: Amit Langote <amitlan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Begin RI fast-path index scan under the switched user id
Date: 2026-08-07 08:05:29
Message-ID: E1wsFa5-00000000YM8-45zN@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Begin RI fast-path index scan under the switched user id

ri_FastPathCheck() called index_beginscan() before switching to the
referenced relation's owner for the permission check and probe. For
btree this has no consequence, but starting the scan before the user id
switch sets a poor example for code dealing with out-of-tree access
methods, whose beginscan could observe the wrong user id. Move
index_beginscan() after the SetUserIdAndSecContext() call.

Reported-by: Noah Misch <noah(at)leadboat(dot)com>
Reviewed-by: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Discussion: https://postgr.es/m/20260705210533.ee.noahmisch@microsoft.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7c1c2f0b8d837fa49df434ecc4438e7d3476144e

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

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Langote 2026-08-07 08:26:44 pgsql: Fire fast-path FK batches inside the deferred trigger loop
Previous Message Amit Langote 2026-08-07 08:05:15 pgsql: Begin RI fast-path index scan under the switched user id