model-writtenrun 2386 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Ronan Dunklau opened the discussion with examples showing SQL functions using generic plans where PL/pgSQL could specialize for parameter values #1; Tom Lane supported using the plan cache and also wanted earlier DDL statements to affect later statements within a function #2.
- After a long gap, Alexander Pyhalov supplied a prototype that improved partition pruning through custom plans, but retained plans only for the calling query and excluded SQL-body functions with stored query trees #3.
- Alexander Korotkov recommended revising StmtPlanRequiresRevalidation() and treating session-level caching as a separate step #4; Pyhalov followed that direction and fixed handling of statements removed by DO INSTEAD NOTHING rules #5.
- After the January rebase #7, Tom Lane identified broken revalidation without a source tree, requested explicit support for analyzed Query trees, opposed the extra GUC, and asked to preserve useful error context #8; Pyhalov implemented those changes, added RLS invalidation tests, and fixed replanning memory growth #9 #10.
- Pavel Stehule's corrected benchmarks exposed a substantial slowdown for non-inlined functions #14, and Tom confirmed that rebuilding custom plans on every outer-query execution made persistent caching necessary before the feature could land #15.
- Pyhalov added a session-level cache, corrected locking and tree copying during revalidation, and released plans after execution #17; his initial return-type solution avoided saving adjusted plans and used a callback to restore coercions after invalidation.
- Pavel confirmed substantial speedups but reported small regressions in unrelated execution paths #18; cross-platform measurements led Tom to suspect build or measurement variation #21, and later Pavel found roughly halved runtimes in the previously slow cases #28.
- Tom raised recursive cache-lifetime concerns, objected to sacrificing caching for coerced results, and requested separate snapshot and revalidation decisions #23; Pyhalov responded by adjusting targetlists before creating cached plans and adding a parser-side query classification helper #27.
- Tom separated the plan-cache infrastructure into its own patch, removed an obsolete preparatory refactor, and challenged the changed extension-schema behavior and missing return-type tests #32; Pyhalov then merged the cache integration patches, expanded comments, and added a DISCARD PLANS reproducer #33.
- Pyhalov subsequently demonstrated that recursive execution could invalidate a function while its cached plans were still needed #34; Tom chose to extract PL/pgSQL's established cache-management code rather than maintain a separate implementation #35.
- Tom's six-patch redesign introduced shared funccache.c, output-rowtype cache keys, post-rewrite callbacks, and per-execution state, while planning one function query at a time #36; it also required the physically last source statement to produce the result and dropped the earlier rules test because it no longer distinguished patched behavior.
- Pavel reported that the redesigned series passed all tests #37, and Pyhalov reported successful corner-case and memory-leak checks #38; further execution-state simplification and allocation refinements were left for later #36 #39.
- Tom reconsidered deferring incremental parse analysis because the intermediate behavior treated CREATE and ALTER cases inconsistently, then added delayed analysis and rewrite to the full series #40, completing the original goal for old-style SQL functions.
- Tom squashed the final seven-patch series #40 into 0dca5d68d7 with only code-ordering and comment cleanup, crediting Alexander Pyhalov as author, himself as co-author, and Pavel Stehule as reviewer; he announced the landing before feature freeze #41.
- Alexander Lakhin then found an assertion failure when an empty polymorphic function returned a non-VOID type #43; Tom acknowledged the missed case #44 and added runtime validation plus regression coverage in dbd437e670.
- Lakhin next reported invalid memory access when a function was called again after parse analysis failed #45 and confirmed that the failing first call was intentional #47; Tom fixed mutation of cached source trees by copying them before analysis or rewrite in 0f43083d16.
- Tom traced buildfarm timeouts to repeated replanning of deliberately non-inlineable functions in the deadlock-parallel isolation test under forced cache invalidation #48; 837cc73af2 replaced those wrappers with internal-language aliases and inlineable wrappers, preserving invalidation testing.
- The thread ends with Tom explaining the landed isolation-test solution #49; the feature and three follow-up fixes are committed, while the separately noted infinite_recurse slowdown has no resolution recorded here #48.