model-writtenrun 1271 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Richard Guo opened the thread with DISTINCT ON losing rows and ORDER BY producing incorrect ordering because equivalence-class processing ignored grouping-set nullability, proposing a dummy range-table index to distinguish nullable expressions in #1.
- Alena Rybakina tested the initial patch and suggested CUBE coverage in #3; Richard considered the existing tests sufficient in #4 and subsequently extended placeholder wrapping to eligible variable-free expressions in #5.
- Tom Lane argued that equivalence-class adjustments could not solve the broader grouping-expression problems and proposed a real grouping-output RTE with parser-level expression substitution in #6.
- After several months, Richard implemented that architecture in #9, then added deparsing and regression support in #10 and merged substitution into the ungrouped-column checker to handle flattened join aliases correctly in #11.
- Richard restored the original nullability fix as a second patch in #12, marking grouping expressions with the real grouping RTE's index and removing that marker where expressions execute below grouping.
- A grouped boolean HAVING expression exposed an implicit-AND assertion, leading Richard to move grouping substitution before expression preprocessing in #13; subsequent revisions added guards, window-ordering tests, formatting, and broader regression coverage in #14 and #15.
- Ashutosh Bapat challenged the RTE design and reviewed implementation details in #16, and Richard explained why shared grouping subqueries required parser infrastructure rather than equivalence-class changes in #18.
- Andres Freund identified ABI and API incompatibilities in #17, Tom confirmed the catalog-version requirement in #20, and Richard limited RTE_GROUP creation to queries with actual grouping expressions in #22.
- Sutou Kouhei reviewed the parser patch's comments, naming, and unnamed-column handling in #24, prompting the comment correction and ?column? fallback in #25.
- Ashutosh questioned shared evaluation of grouping subqueries in #26, Paul George contributed volatile-function and alias experiments in #27, and Richard's investigation in #28 and #29 supported sharing nonvolatile grouping expressions while leaving volatile-expression semantics unsettled.
- Robert Haas asked for a smaller backpatchable fix in #30, but Tom concluded that the structural changes needed a full beta cycle and should proceed only in a future release in #31.
- Richard added a third patch to unwrap safe PlaceHolderVars and avoid unnecessary sorts on constant grouping keys in #32, while leaving broader placeholder optimizations for separate work.
- Further boolean HAVING examples showed that early substitution could prevent expressions from matching grouping outputs, so Richard reversed the preprocessing order and reprocessed HAVING expressions only when moving them into WHERE in #33.
- Richard moved the broader placeholder-removal optimization to another thread in #34 and landed the first two patches from #33 as 247dea89f7 and f5050f795a, adding catalog-version bumps and extra boolean-expression tests before announcing the landing in #35.
- David Rowley reported an EXISTS/GROUP BY assertion failure in #36; Richard traced it to a grouping RTE surviving removal of GROUP BY in #37 and supplied the cleanup patch in #38.
- The cleanup landed as ffe12d1d22, with hasGroupRTE clearing moved inside the matching-entry branch, and Richard confirmed the push in #39.
- In February 2026, Tom warned that deleting the grouping RTE could shift subsequent range-table indexes and proposed in-place conversion to RTE_RESULT in #40; Richard supplied that change in #41.
- Tom approved the safety fix after investigating possible counterexamples in #42, and it landed unchanged as 77c7a17a6e; Richard's final message #43 confirms the push and PostgreSQL 18 backpatch, with the main fixes complete and placeholder optimization remaining separate.