model-writtenrun 2341 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Kaimeh reported that a DISTINCT array_agg query whose FILTER excludes invalid integer inputs succeeds on PostgreSQL 15 but raises an invalid-input error on PostgreSQL 16 and 17 #1.
- Tom Lane traced the regression to presorted aggregation evaluating aggregate arguments before FILTER and proposed disabling that optimization for potentially unsafe expressions while allowing simple Vars and possibly RelabelType wrappers #2.
- David Rowley supplied an experimental patch accepting Vars and Consts, including those exposed by stripping implicit coercions; he also identified a separate costing problem and explained why rejecting a RowExpr changed otherwise unordered SQL/JSON results #3.
- Tom advocated disabling presorted aggregation for all filtered aggregates because selective filters can make sorting first expensive, while David argued that a blanket restriction could regress queries benefiting from index-provided ordering #4 #5 #6.
- David clarified that only the costing improvement should be deferred, outlined competing aggregate paths with explicit internal-sort costs as possible PostgreSQL 19 work, and reaffirmed his preference for the targeted correctness fix #7 #8 #9 #10.
- David committed the patch from #3 as d47f922246, narrowing coercion handling to RelabelType wrappers, revising regression tests, and updating SQL/JSON expected output; the fix was backpatched through PostgreSQL 16.
- The thread ended with David confirming the push ahead of upcoming minor releases and explaining that the narrower cast handling avoids treating equivalent explicit and implicit conversions differently; broader aggregate costing remained future work #11 #8.