model-writtenrun 2916 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Alexander Lakhin reported that an expression index combined with a flattened UNION ALL could produce a “could not find pathkey item to sort” error in #1, and Tom Lane traced the failure to the original introduction of MergeAppend in #4.
- Richard Guo supplied a simpler reproducer in #3 and explained in #10 that appendrel substitution can introduce arbitrary targetlist expressions that find_computable_ec_member() incorrectly assumes are Vars or quasi-Vars; he also floated wrapping those expressions in PlaceHolderVars.
- Andrei Lepikhov proposed searching inside targetlist expressions for the required variables in #12.
- Tom Lane established that the sort expression is added to the same plan node's targetlist, making its existing input variables available, and refactored Andrei's solution to extract those variables once in #15; Richard Guo endorsed that reasoning in #16.
- Andrei Lepikhov supplied a relation-bitmap alternative while approving Tom's draft in #17, but questioned whether merely having the required relations guarantees that every needed value remains available.
- The draft in #15 landed as 76de4b182c with unchanged production edits and added regression tests; the fix was backpatched through PostgreSQL 13, while PostgreSQL 12 was omitted because adapting it near its final release posed disproportionate regression risk.
- In the final reply #18, Tom Lane concluded that the relation-level shortcut might only be reliable for appendrel children and was not worth a separate code path, leaving the conservative fix committed and the alternative unused.