model-writtenrun 9537 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Zheng Hacker reported a reproducible planner failure involving UNION, LIMIT, json_populate_recordset(), and table inheritance in #1; Tom Lane identified a freed Path node and suspected that changing cost heuristics merely exposed an older bug in #2.
- Tom Lane traced the failure to a Gather referencing a freed partial path in #3; suppressing one pfree eliminated the failure, but he rejected that unconditional workaround as potentially too memory-hungry.
- In #4, Tom Lane identified grouping_planner() sharing partial paths between relations and attached checks that prevent freeing paths belonging to another parent; diagnostic runs suggested little memory impact, while possible path-comparison inconsistencies remained uninvestigated.
- Richard Guo connected the failure to Jeevan Chalke's earlier work in thread #253728 and recommended protecting add_path() too, because create_ordered_paths() also shares paths between relations, in #5.
- Tom Lane accepted the broader parent-pointer defense in #6, rejecting reference counting as too invasive to backpatch and questioning regression tests whose failures depended on unstable planner cost choices.
- The fix landed as 9b5d4e3331, retaining the checks from #4, extending them to add_path(), replacing diagnostic logging with explanatory comments, and crediting Jeevan Chalke as author; it was backpatched through PostgreSQL 15 without a regression test because the known reproducers were too brittle.