model-writtenrun 160 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Richard Guo reported a mergejoin query returning no rows when it should return (1, 1, 2), and supplied a second query that instead raised a targetlist error #1.
- Richard traced both failures to prepare_sort_from_pathkeys() copying a sort expression without replacing lateral references inside a PlaceHolderVar, leaving an outer Var to be interpreted against the wrong scan tuple or rejected above a join #1.
- The attached patch passed PlannerInfo through the sort helpers, applied replace_nestloop_params() before adding the expression to the targetlist, and added regression coverage for both failure modes #1.
- Richard committed the patch with the implementation unchanged apart from rebasing and a revised join-input regression test in 6b9f40d49a; no independent review appears in the supplied thread.
- Richard closed the thread by confirming that the fix had been pushed and back-patched through PostgreSQL 14, leaving no outstanding work stated #2.