model-writtenrun 5322 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Martijn van Oosterhout reported a query failure involving set-returning functions, a join, and ORDER BY, with reproduction sensitive to table bloat and plan selection #1; after Tom Lane requested a reproducible case #2, Martijn supplied a script recreating the necessary table layout #3.
- Richard Guo traced the failure to a Gather Merge path that pushed an expression containing unnest() into a scan target list #4, then supplied an inline fix replacing shallow IS_SRF_CALL() checks with recursive expression_returns_set() checks in relation_can_be_sorted_early() #5.
- Tom Lane agreed with the fix and argued that IS_SRF_CALL() should cease being publicly available because its shallow semantics invited misuse, while its specialized use in tlist.c remained legitimate #6.
- Tom Lane could reproduce the failure on older branches but struggled to obtain a stable regression test #7; he traced the different plan on newer branches to changes associated with GROUP BY reordering and questioned why they substantially reduced sort costs for a query without GROUP BY #8.
- Tom Lane committed the recursive checks and macro cleanup without a new regression test as 1aa8dad41f, announcing that decision while leaving the sort-cost discrepancy unresolved #10; he also suggested that the additional set-returning function forced a ProjectSet above the join, affecting whether the faulty plan was selected #11.
- Richard Guo investigated ways to force the faulty Gather Merge plan #12 and then submitted a regression test verified to fail before the fix and succeed afterward #14, clarifying that his reproduction used the earlier code.
- Tom Lane simplified Richard Guo's test, confirmed that it also exposed the failure on older branches, and announced its landing #16; cc11647991 incorporates that revised test and removes the previous ineffective incremental_sort test.
- After Martijn van Oosterhout asked when the fix would be released #15, Tom Lane said it would be included in the following week's releases #17.
- The planner fix and regression test had landed by the thread's final message, but the separate costing question remained open: Dmitry Dolgov identified a group-count estimate of one that removed the expected logarithmic contribution to sort startup costs and suggested that a geometric-mean fallback produced estimates closer to the earlier implementation #18.