FK fast-path bug repro: subxact abort silently drops pending FK checks#39
Draft
NikolayS wants to merge 2 commits into
Draft
FK fast-path bug repro: subxact abort silently drops pending FK checks#39NikolayS wants to merge 2 commits into
NikolayS wants to merge 2 commits into
Conversation
Confirmed that ri_FastPathSubXactCallback() in ri_triggers.c unconditionally NULLs the fast-path cache on any subtransaction abort, discarding pending FK checks for rows that remain live in the parent transaction. This silently bypasses FK enforcement and leaves orphan rows. Tested against upstream/master (commit 84b9d6b, PostgreSQL 19devel). https://claude.ai/code/session_01RH7iZRYK8ZVnx7uMh2KUkg
Track SubTransactionId at cache creation time and only tear down the fast-path cache when the aborting subxact actually encompasses the creation point. Tested: FK violations now correctly detected, valid inserts still succeed, no resource leak warnings. https://claude.ai/code/session_01RH7iZRYK8ZVnx7uMh2KUkg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ri_FastPathSubXactCallback()that silently bypasses FK constraint enforcementri_FastPathSubXactCallback()unconditionally NULLs the fast-path cache on any subtransaction abort, discarding buffered FK checks for rows that remain live in the parent transactionBug details
When an AFTER ROW trigger on a FK table causes an internal subtransaction abort (e.g., PL/pgSQL
BEGIN...EXCEPTION...END),ri_FastPathSubXactCallback()drops the entire fast-path cache. This discards pending FK existence checks that were buffered byri_FastPathBatchAdd()for earlier rows. The result: INSERT succeeds, orphan rows persist, and the constraint is still reported as valid.Test plan
(999, 'bad')succeeds despite no matching PK rowpg_constraint.convalidatedstill reportstrueafter the orphan is createdhttps://claude.ai/code/session_01RH7iZRYK8ZVnx7uMh2KUkg
Generated by Claude Code