On Thu, Aug 13, 2026 at 1:22 Peter Geoghegan <[email protected]> wrote: > On Fri, Jul 31, 2026 at 11:03 PM Peter Geoghegan <[email protected]> wrote: > > The attached isolation test patch (written by Claude code) shows that > > the new RI fast path can get some things wrong when a foreign key uses > > a cross-type equality operator. > > Opus 5 flagged an independent problem in the RI fast path work. This > one appears to be a resource management issue. > > When I run the foreign_key tests with the attached patch applied, I > see these failures: > > # END$$; > # CREATE TRIGGER fp_expand_kit_trg AFTER INSERT ON fp_order > # FOR EACH ROW EXECUTE FUNCTION fp_expand_kit(); > # INSERT INTO fp_order VALUES (1, 1, 1); > # +WARNING: resource was not closed: relation "fp_product" > # +WARNING: resource was not closed: relation "fp_product_pkey" > # +WARNING: resource was not closed: TupleDesc 0x7f7e109a3448 (34085,-1) > # +WARNING: resource was not closed: TupleDesc 0x7f7e109a2cd8 (34068,-1) > # NOTICE: order 1 expanded into 3 order items > > Right afterwards, "Assert(rel->rd_refcnt > 0)" fails within > RelationDecrementReferenceCount().
Thanks, Peter. This is another bug, and a hole in the April fix for nested C-level SPI [1]. That fix made the batch callback lists per query level, but left ri_fastpath_callback_registered global. If an outer FK check has already set the flag, the nested level does not register its own ri_FastPathEndBatch() callback. When the nested portal ends, its ResourceOwner warns about and releases the still-cached relation references and TupleDesc pins. The outer callback later calls ri_FastPathTeardown() on the same entries, accounting for the refcount assertion. This exact case should be addressed by 0001 from the subtransaction series [2], which registers the callback per query level and tears down only that level’s entries. I am checking whether it also handles nested firing involving the same constraint before committing that series. [1] https://postgr.es/m/caeg7pwckf01fmdqfaf-hzu_pynmyscy_otid-pe9uw3bj6g...@mail.gmail.com [2] https://postgr.es/m/ca+hiwqgha3tc6mzfslylrvwysdrmpkb1tqkh2jgd3htkggz...@mail.gmail.com - Amit >
