ri_FastPathCheck() invokes two functions on the FK values: the equality operator's function, via the ScanKey the index AM evaluates, and, when the FK column's type differs from the PK column's, the implicit cast function. The SPI path gets EXECUTE on both checked by ExecInitFunc() when it initializes the generated query, as the referenced table's owner, but the fast path performed neither check. Add ri_CheckFunctionPermissions() and call it once the fast-path metadata is populated, under the switch to the referenced table's owner, so the checks happen at the same point as the existing relation permission check. Add a regression test for each function, reaching the fast path through per-row validation of a new constraint, and repeat each against a partitioned referenced table, which takes the SPI path, to show that the two behave identically. Reported-by: Nikolay Samokhvalov <nik@postgres.ai> (offlist) Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com> Discussion: https://postgr.es/m/CA+HiwqGH+b7sXmsH8sT18diujbheSObWs0gWXqLZqRccMKvZAA@mail.gmail.com Backpatch-through: 19
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.