model-writtenrun 8519 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Robins Tharakan reported input-order-dependent SEARCH/CYCLE results with DISTINCT in recursive queries and an assertion failure on PostgreSQL 18 and later, supplying reproductions in #1.
- Tom Lane traced the assertion to the rewriter adding columns without updating DISTINCT semantics, weighed extending DISTINCT against converting it to DISTINCT ON, and identified mutable casts between cycle-mark types as a complication in #2 and #3.
- Tom proposed computing the extra columns in the parent query while leaving the recursive subquery's target list unchanged, interpreting that as the SQL specification's intended rewrite in #4.
- Tom abandoned that approach because the sequence column could not be obtained from the subquery and posted a patch converting the internal DISTINCT representation to DISTINCT ON, restoring pre-v18 behavior, in the thread's final message #5.
- After the final message, Tom committed the posted code unchanged with an added regression test as 65ebed1f5e; the fix was backpatched through PostgreSQL 15, and no further review or outstanding patch appears in the supplied thread.