model-writtenrun 7067 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Tom Lane reported that repeated SQL-function calls within one query could be about 50% slower after the v18 changes and proposed five patches restoring reusable execution state while controlling memory leakage, reducing his measured penalty to about 5%; he initially considered avoiding tuplestores or junkfilters outside v18's scope #1.
- Robert Haas supported addressing the regression without claiming code review, and Pavel Stehule reported passing tests and about a 5% improvement over master on his notebook #2 #3.
- Bruce Momjian connected the problem to SQL-standard function-body conversions, but Tom clarified that the slowdown concerned planning and execution machinery largely independent of function-body syntax #4 #5 #7 #8.
- After the performance changes landed, Alexander Lakhin reported a SQLsmith-derived aggregate query that crashed with memory corruption, and Tom reproduced it #9 #10.
- Tom attached a small follow-up that cleared result slots before their tuple storage disappeared, fixing the reproducer while leaving him uncertain why older code had been safe #11.
- Tom then proposed using his separately posted optimization that eliminated tuplestore_gettupleslot calls, preferring that broader solution over a temporary v18-specific fix #12.
- Tom resolved the lifetime issue: disk-spilled tuples were allocated in the caller's now-short-lived context while the persistent slot retained responsibility for freeing them; his final message still favored eliminating unnecessary tuplestores and raised an unresolved concern about resource-owner access in released branches #13.
- The subsequent commit applied the unchanged patch from #589747 in thread #51467, retaining single-row results in a materialized slot and reserving tuplestores for non-lazy set results; that separately developed solution superseded this thread's local slot-clearing attachment #11 e83a8ae447.