model-writtenrun 8102 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Pavel Stehule reported that repeated procedure calls consumed about 2.2 GB and took ten seconds, compared with roughly one second and negligible memory growth for equivalent function calls #1.
- Pavel traced the problem to repeated planning and delayed plan cleanup in non-atomic CALL execution, posted an explicit-freeing fix #2, discovered that it broke recursion #4, and revised it to track plan ownership while leaving performance and smaller leaks unresolved #5.
- Ranier Vilela tested a modified patch and submitted an experimental refactoring #6 #10, but Pavel objected to mixing refactoring with the bugfix, and those changes were not carried forward #13.
- Amit Khandekar demonstrated that recursive calls could clear the shared plan pointer before its owner freed it #17, prompting Pavel to retain a local pointer #18; Amit's subsequent review requested a consistency assertion #19, which Pavel added #20.
- Pavel then submitted both the small memory fix and a broader alternative that cached CALL plans using a fragile flag to coordinate cleanup across transaction boundaries, reporting improvements in both memory use and execution time #22.
- Tom Lane found that the small fix still leaked output-target structures and catalog lookup allocations, and supplied a rework using transient allocation contexts, invocation-local plans, and restoration of the previous plan pointer; his tests showed no memory growth on Pavel's example #25.
- Tom rejected the fragile-plan approach and proposed holding plan references through a resource owner tied to procedure execution instead, while limiting backpatches to the memory fix #25; Pavel agreed to pursue the broader performance work separately for PostgreSQL 14 #26.
- Tom committed #25 with only comment edits as a6b1f5365d, crediting himself and Pavel and backpatching through PostgreSQL 11; he closed the commitfest entry and requested a new thread for the remaining performance work #27, after which Pavel thanked him #28.