model-writtenrun 6245 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Mark Dilger reported a regex compilation assertion, reduced it to nested captures followed by a zero-repeat backreference, and supplied a regex-generating script to find more failures #1 #2 #4.
- Tom Lane initially suspected zero-repeat handling, then established that the failure was new in PostgreSQL 14 and bisected it to his optimization that avoided extra capture nodes #3 #5 #6.
- Tom's first patch stored capture NFA endpoints directly instead of retaining subRE pointers; it fixed the reported cases and survived preliminary testing with Mark's generator #7.
- Tom then identified the underlying use-after-free: an optimization recycled a child subRE still referenced by capture bookkeeping, with failure appearing only when that node was reused #8.
- Tom supplied an alternate fix that changed parseqatom() to free the caller's node and preserve the referenced child, while proposing to retain the first patch as additional protection against endpoint changes #8.
- The alternate patch landed unchanged as cc1868799c, followed by the first patch's bookkeeping change with adjusted nested-capture endpoints and expanded comments as cb76fbd7ec; the shared regression test landed with the former commit.
- Tom reconsidered the endpoint-only bookkeeping because his planned REG_NOSUB optimization needed access to capturing subREs, so 00116dee5a reverted that data structure change, preserved existing capture endpoints instead, and corrected which capturing node was recorded #9.
- After the commits, Mark reported a crash and changed results with the first attachment alone, then tested the alternate attachment and concluded that its changed results were correct after revisiting his interpretation of captures #10 #11 #12.
- Tom clarified that the committed code agreed with PostgreSQL 13 on those examples, and Mark realized he had been testing an older checkout before updating to the committed version #13 #14 #15.
- Mark's final comparison confirmed that the previously discussed expressions agreed between PostgreSQL 13 and updated master; Tom attributed the remaining differences to separate intentional backreference and character-class improvements, leaving all fixes from this thread committed with no outstanding issue identified #16 #17.