model-writtenrun 3513 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Justin Pryzby reported that PostgreSQL 16 could fail with “could not find pathkey item to sort” when partitionwise aggregation was enabled for a partitioned table and a DISTINCT aggregate #1.
- Richard Guo proposed adding ordered-aggregate arguments as resjunk target entries, which fixed the reported query but caused an assertion failure in the trigger regression tests #2.
- David Rowley explained that aggregate input columns cannot generally remain outputs after grouping and replaced Richard’s approach with a helper that retained only the prefix of pathkeys represented in the aggregate target #3.
- David measured planning time increasing from roughly 24 ms to 41 ms with the generic helper on a thousand-partition example, prompting a cheaper implementation that checked group_pathkeys and truncated the list to num_groupby_pathkeys #4.
- David then concluded that a list-length check was sufficient and supplied the simplified fix alongside experimental assertions checking pathkeys against path targets; he proposed committing the fix without a dedicated regression test and deferred the assertions because of possible overhead #5.
- Richard endorsed the fix and explained that even computable aggregate-ordering expressions could safely be removed because their extra ordering was redundant, resolving the clarification David had requested #6 #7 #8.
- David committed the create_agg_path() fix from #5, with only formatting changes and without the experimental assertion attachment, as d8a295389b, then announced the landing #9.
- David supplied separate planner timing instrumentation and measured about 1.5% overhead for the assertions using the minimum regression-suite timings; Richard considered that acceptable for assertion builds, but the thread records no landing of the assertions or timing instrumentation #9 #10.
- Months later, Alexander Lakhin reported another reproducer involving partitionwise aggregation and parallel planning, and David supplied a separate fix trimming aggregate-only pathkeys in gather_grouping_paths() #11 #12.
- David also suspected that partitionwise aggregation left incorrect target expressions on a relation; Ashutosh Bapat investigated the base and upper relation calls under the debugger, and David explained why aggregate ordering initially required both columns in the pathkeys #12 #13 #14.
- David committed the gather_grouping_paths() patch from #12 as 4169850f0b, adding the missing trimmed-pathkeys argument for ordinary sorting and improving the comment, while initially leaving the suspected target-expression issue open #15.
- After Ashutosh requested further clarification, David rechecked the suspicious plan and found it was a valid non-partitionwise aggregation path whose target still contained the input column, withdrawing that concern; both reported errors were fixed, with no further correctness fix proposed at the thread’s end #16 #17.