| 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:17 |
| Message-ID: | E1wsF3x-00000000Y8E-0RVm@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
------
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Langote | 2026-08-07 08:05:15 | pgsql: Begin RI fast-path index scan under the switched user id |
| Previous Message | Amit Langote | 2026-08-07 07:32:03 | pgsql: Restrict RI fast-path FK check to btree referenced indexes |