Restrict RI fast-path FK check to btree referenced indexes The RI fast-path check probes the referenced index directly and, for single-column keys, uses SK_SEARCHARRAY. Both assume the index is a btree. A comment claimed "PK indexes are always btree", but a foreign key's referenced index need not be a primary key: transformFkeyCheckAttrs() accepts any unique (or, for temporal keys, exclusion) index, so an out-of-tree access method advertising amcanunique could supply a non-btree index reachable by the fast path.
Add pk_index_is_btree to RI_ConstraintInfo, set from the referenced index's access method when the constraint is loaded, and make ri_fastpath_is_applicable() return false for non-btree indexes so such constraints fall back to the SPI path. Reported-by: Noah Misch <[email protected]> Reviewed-by: Ayush Tiwari <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/edc92e0ff9572e41dc2d2fc14fbab313fa9d7bc5 Modified Files -------------- src/backend/utils/adt/ri_triggers.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
