model-writtenrun 8615 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Justin Pryzby brought the sqlsmith incremental-sort crash to pgsql-hackers in #1, and Tomas Vondra traced it to set-operation Vars with varno zero reaching estimate_num_groups and failing in find_base_rel in #2.
- Tomas posted #3 to detect those Vars and assume one group per input row, explaining that redesigning set-operation representation was too large a change at this stage and that the original target list was not readily available.
- Justin confirmed that the patch fixed the reproducer and survived twenty minutes of sqlsmith testing in #4; James Coleman then examined the available planner information and explained the costing tradeoffs between assuming uniqueness and a single group in #5 and #7.
- Richard Guo supplied a minimal UNION reproducer in #8, then proposed avoiding the additional sort by matching UNION's sort keys to the requested output order in #9 and attached that independent optimization in #10.
- James questioned whether the optimization belonged in this bugfix discussion in #12, while Tomas identified competing sort-cost considerations and an EXCEPT case that still crashed, arguing against a behavior change after feature freeze in #13 and #14.
- Tomas compared single-group, unique-row and intermediate fallback estimates in #15; Tom Lane advised against either extreme and suggested DEFAULT_NUM_DISTINCT in #17.
- Richard continued to defend sort-key reordering as useful in #18 and acknowledged that EXCEPT and INTERSECT also needed handling in #19, but no revised optimization patch or landing appears in this thread.
- James proposed a separate default for presorted groups in #20, but Tomas chose the existing DEFAULT_NUM_DISTINCT because there was no evidence for a better value in #21.
- Tomas committed de0dc1a847 from #3, changing the fallback estimate, detecting nested Vars with pull_varnos and adding a regression test; his announcement in #22 left mixed known-and-unknown expression estimates unimplemented because it was unclear whether that case could occur.
- After the commit, Richard verified the fix and identified redundant RelabelType stripping in #23; Tomas agreed to remove it but considered explicit bitmap freeing unnecessary in #24, and Tom Lane supported those conclusions in the final message, #25.
- The crash fix was landed by the thread's end, while sort-key reordering remained unlanded; the agreed cleanup subsequently landed as 60fbb4d762 from the newer patch #449223 in thread #42306.