| From: | Amit Langote <amitlan(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Invalidate RI fast-path metadata on operator family changes |
| Date: | 2026-09-19 06:59:32 |
| Message-ID: | E1x7p2q-00000000Mtb-1hMC@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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 <nik(at)postgres(dot)ai>
Author: Nikolay Samokhvalov <nik(at)postgres(dot)ai>
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Langote | 2026-09-19 06:59:46 | pgsql: Invalidate RI fast-path metadata on operator family changes |
| Previous Message | Michael Paquier | 2026-09-19 04:50:28 | pgsql: Add test for logical decoding with an oid8 TOAST table and OID > |