model-writtenrun 4863 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Andrei Lepikhov reported excessive planning memory for generated queries containing roughly 10,000 UNION ALL branches and proposed skipping unnecessary PlaceHolderVar walks and unrelated AppendRelInfo updates #1.
- Tom Lane showed that older releases also suffered when the branches contained FROM clauses, then extended the optimization to return immediately after updating the containing AppendRelInfo and added stack-depth and cancellation checks; his revision passed check-world #2.
- Richard Guo identified an obsolete hasSubLinks condition and a redundant lastPHId check #3; Tom Lane acknowledged the findings and traced the obsolete condition to the removal of FlattenedSubLink nodes #4 #5.
- Andrei Lepikhov endorsed Lane's revised approach while raising a possible future SQL-standard concern #6, which Lane later dismissed because allowing LATERAL references between UNION ALL branches would also invalidate other existing code #7.
- Tom Lane split the defenses from #2 into 5beb7881fb, added stack checks in two more recursive functions, and backpatched this safer portion because the performance change was considered too risky for stable branches.
- The optimization portion of #2 landed with Richard Guo's cleanups as e42e312430; Lane closed the thread by confirming that the main fix was on HEAD and the recursion checks were on all branches #7.