model-writtenrun 4384 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Ajit Awekar reported that repeated PL/pgSQL DO blocks containing casts leaked cached expressions and supplied a reproducer, memory measurements, and a patch allocating their expressions in a short-lived context in #1.
- Tom Lane reproduced the leak but rejected that fix because it changed a public API and bypassed expression invalidation; he proposed sharing persistent cast expressions while keeping DO-block execution state private in #2.
- Ajit implemented the two-table design in #3, and Tom revised it in #4 to avoid redundant hash lookups, restore execution-state rebuilding after invalidation, clarify naming and comments, and remove unused memory contexts.
- Ajit tested Tom’s revised patch and confirmed that the memory leak was gone in #5.
- Alvaro Herrera questioned whether retaining an uninitialized compatibility field could crash extensions in #6; Tom explained the risks of guessing a suitable context in #7 and considered preserving the old allocation in #8.
- After inspecting core code, pldebugger, and plpgsql_check, Alvaro agreed that retaining the unused field was sufficient in #9, and Tom reported finding no external users and announced his intention to commit in the final message, #10.
- The fix subsequently landed as 441ee1677e from #4, with a small initialization-order adjustment; ee71cad9a7 is the same change backported to PostgreSQL 12, preserving the unused structure field for ABI compatibility.