Invalidate RI fast-path metadata on operator family changes 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 <[email protected]> Author: Nikolay Samokhvalov <[email protected]> Discussion: https://www.postgr.es/m/CAM527d9PzFzagr67N0%3DEx2ng1p5HzrcAszy3j5OoZKHXQMARXA%40mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c86738fd4a4c086353138d199190a34e738e6dd3 Modified Files -------------- src/backend/utils/adt/ri_triggers.c | 45 ++++++++++++++++++++- src/test/regress/expected/foreign_key.out | 67 +++++++++++++++++++++++++++++++ src/test/regress/sql/foreign_key.sql | 56 ++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 2 deletions(-)
