The RI fast path checks a foreign key by probing the referenced unique index directly, using the equality operator recorded for the constraint. Whether the fast path can be used is decided once and cached in RI_ConstraintInfo, and that cache is invalidated on pg_constraint changes but not on pg_amop. So after an ALTER OPERATOR FAMILY drops the recorded operator and adds another in its place, the cached decision is stale, and the next fast-path check probes the index with an operator no longer in the opfamily and errors out with "operator XXX is not a member of opfamily XXX". The SPI path is unaffected, because the planner just stops matching the index. To fix, register an AMOPOPID syscache callback to flush the RI cache on pg_amop changes, and have ri_check_fastpath_index() recheck that the recorded operator is still the equality member of the index's opfamily, falling back to SPI when it is not. Add regression test coverage. Reported-by: Nikolay Samokhvalov <nik@postgres.ai> Author: Nikolay Samokhvalov <nik@postgres.ai> Discussion: https://www.postgr.es/m/CAM527d9PzFzagr67N0%3DEx2ng1p5HzrcAszy3j5OoZKHXQMARXA%40mail.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/.