Skip to content

FK fast-path bug repro: subxact abort silently drops pending FK checks#39

Draft
NikolayS wants to merge 2 commits into
masterfrom
claude/postgres-fk-fastpath-bug-HOyam
Draft

FK fast-path bug repro: subxact abort silently drops pending FK checks#39
NikolayS wants to merge 2 commits into
masterfrom
claude/postgres-fk-fastpath-bug-HOyam

Conversation

@NikolayS

Copy link
Copy Markdown
Owner

Summary

  • Confirmed a bug in PostgreSQL 19devel's ri_FastPathSubXactCallback() that silently bypasses FK constraint enforcement
  • ri_FastPathSubXactCallback() unconditionally NULLs the fast-path cache on any subtransaction abort, discarding buffered FK checks for rows that remain live in the parent transaction
  • Includes a reproduction script and detailed root-cause analysis

Bug 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 by ri_FastPathBatchAdd() for earlier rows. The result: INSERT succeeds, orphan rows persist, and the constraint is still reported as valid.

Test plan

  • Built upstream/master (commit 84b9d6b) and ran the reproduction script
  • Confirmed INSERT of (999, 'bad') succeeds despite no matching PK row
  • Confirmed resource-leak warnings appear (relations owned by parent transaction are abandoned)
  • Confirmed pg_constraint.convalidated still reports true after the orphan is created

https://claude.ai/code/session_01RH7iZRYK8ZVnx7uMh2KUkg


Generated by Claude Code

claude added 2 commits May 27, 2026 12:04
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants