| From: | Amit Langote <amitlan(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Restrict RI fast-path FK check to btree referenced indexes |
| Date: | 2026-08-07 07:32:03 |
| Message-ID: | E1wsF3j-00000000Y6h-01rp@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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 <noah(at)leadboat(dot)com>
Reviewed-by: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Discussion: https://postgr.es/m/20260705210533.ee.noahmisch@microsoft.com
Backpatch-through: 19
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/8c0aa08c159494a86fe5c3206e8a9f5de850112e
Modified Files
--------------
src/backend/utils/adt/ri_triggers.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Langote | 2026-08-07 07:32:17 | pgsql: Restrict RI fast-path FK check to btree referenced indexes |
| Previous Message | Amit Langote | 2026-08-07 07:28:41 | pgsql: Remove stale comment on ri_FastPathCheck() |