Fix RI fast-path for domain-typed FK columns
Amit Langote <amitlan@postgresql.org>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/utils/adt/ri_triggers.c | modified | +4 −3 |
| src/test/regress/expected/foreign_key.out | modified | +15 −0 |
| src/test/regress/sql/foreign_key.sql | modified | +14 −0 |
Discussion
- Fast-path FK checks reject valid inserts for domain-typed FK columns 5 messages · 2026-06-12 → 2026-06-17