1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00
Amit Langote 6aecabcd5e Use SPI for RI checks whose FK values need a cast function
When the FK column's type needs a cast function to reach the equality
operator's input type, the RI fast path calls that function directly.
The SPI path instead applies the cast as an expression in its query,
which takes care of the function's declared arguments, its input
collation, a NULL result, volatility, and replanning when the function
changes.  The direct call doesn't cover all of that; for example, a
NULL result raises an internal error rather than a foreign key
violation, and if the cast's function is dropped and replaced, later
checks fail with "cache lookup failed for function".  Coercions that
aren't a call to one function, array coercion and coercion via I/O,
fail outright with "no conversion function".

Rather than replicate expression evaluation, leave FK values that
aren't binary-coercible to the operator's input type to SPI.  The fast
path keeps handling cross-type operators, domains and binary-compatible
types.  As eligibility now depends on pg_cast, invalidate cached
constraint information on pg_cast changes too.

Because the check needs catalog lookups, it is made in
ri_check_fastpath_index(), which caches its result in fastpath_state
until the constraint's cached information is invalidated, rather than
for every row in ri_fastpath_is_applicable().

The two tests that used a cast function to exercise fast-path code that
still exists (metadata invalidation and the active snapshot) now use
the equality function of a custom opclass, the only user code a
fast-path check still runs.

The fast-path code that calls cast functions is now unused; the next
commit removes it.

Reported-by: Nikolay Samokhvalov <nik@postgres.ai>
Reported-by: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Discussion: https://postgr.es/m/CAM527d9BgPjeOOYmbCBTd57R145qHCk-dzw9qNq+nOrDq1j__A@mail.gmail.com
Backpatch-through: 19
2026-10-15 15:42:18 +09:00
2026-07-17 11:48:35 -04:00
2022-12-04 15:23:00 -05:00
2024-11-05 13:56:02 +01:00
2026-09-24 11:15:27 +02:00
2026-09-24 11:15:27 +02:00
2026-01-01 13:24:10 -05:00
2020-02-10 20:47:50 +01:00
2026-02-23 13:34:22 -05:00
2026-09-24 11:15:27 +02:00

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/.

Description
Зеркало официального репозитория PostgreSQL GIT
Readme 1.3 GiB
Languages
C 83.9%
PLpgSQL 6.2%
Perl 5.4%
Yacc 1.2%
Meson 0.7%
Other 2.4%