agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix RI fast-path for domain-typed FK columns
Date: Wed, 17 Jun 2026 02:17:53 +0000
Message-ID: <E1wZfqj-000esG-0l@gemulon.postgresql.org> (raw)

Fix RI fast-path for domain-typed FK columns

The RI fast path is the first caller to pass a cross-type pf_eq_oprs
operator to ri_HashCompareOp().  Its test for whether a cast can be
skipped, "typeid == righttype", failed when the FK column was a domain,
since typeid is then the domain OID rather than its base type.  The code
concluded no usable conversion existed and threw "no conversion function
from <domain> to <type>" for every valid row.

Look through the domain to its base type.  When pfeqop comes directly
from the index opfamily its right-hand input is getBaseType(fktype), so
getBaseType(typeid) == righttype is the correct test; the PK = PK
fallback (right-hand input opcintype) still fails that test and falls
through to the existing cast lookup unchanged.

Oversight in commit 2da86c1.

Reported-by: Ewan Young <kdbase.hack@gmail.com>
Author: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/CAON2xHNDFC4cX2atvTpMuC=cK9y7q4J+n3+15w4148AohXEc1w@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/68ace967c16bcd5fae87f13678b74ab5c5ea1a0f

Modified Files
--------------
src/backend/utils/adt/ri_triggers.c       |  7 ++++---
src/test/regress/expected/foreign_key.out | 15 +++++++++++++++
src/test/regress/sql/foreign_key.sql      | 14 ++++++++++++++
3 files changed, 33 insertions(+), 3 deletions(-)



Message-ID: <E1wZfqj-000esG-0l@gemulon.postgresql.org>
Permalink:  ../E1wZfqj-000esG-0l@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wZfqj-000esG-0l@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: Fix RI fast-path for domain-typed FK columns
  In-Reply-To: <E1wZfqj-000esG-0l@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