agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedFrom: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Invalidate RI fast-path metadata on operator family changes
Date: Sat, 19 Sep 2026 06:59:32 +0000
Message-ID: <E1x7p2q-00000000Mtb-1hMC@gemulon.postgresql.org> (raw)
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@postgres.ai>
Author: Nikolay Samokhvalov <nik@postgres.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(-)
view thread (13+ messages) latest in thread
Message-ID: <E1x7p2q-00000000Mtb-1hMC@gemulon.postgresql.org>
Permalink: ../E1x7p2q-00000000Mtb-1hMC@gemulon.postgresql.org/
Also on: postgresql.org/message-id/E1x7p2q-00000000Mtb-1hMC@gemulon.postgresql.org
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: amitlan@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Invalidate RI fast-path metadata on operator family changes
In-Reply-To: <E1x7p2q-00000000Mtb-1hMC@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox