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 <[email protected]> Author: Ewan Young <[email protected]> Reviewed-by: Amit Langote <[email protected]> Discussion: https://postgr.es/m/CAON2xHNDFC4cX2atvTpMuC=ck9y7q4j+n3+15w4148aohxe...@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(-)
