model-writtenrun 2233 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Tom Lane discovered that ExecInitModifyTable modified its input plan tree while investigating Valgrind leakage reports, and requested a fix because executor plan trees must remain read-only #1.
- Robert Haas asked about automatic detection, Isaac Morland suggested const declarations, and Tom explained that const does not propagate through pointer fields and pointed to an existing testing proposal; no general enforcement patch emerged here #2 #3 #4 #6.
- Andres Freund established that the planner already supplies a suitable targetlist: differences after pruning affect variable references but not the output slot's required types, so the executor assignment can simply be removed; Tom independently confirmed this reasoning and treated Andres's projection-type mismatch findings as a separate issue #8 #9 #10.
- Tom posted the initial assignment-removal patch and considered backpatching because future changes might make the currently harmless mutation dangerous #11.
- Andres identified a second unnecessary assignment in the branch without RETURNING and demonstrated changed EXPLAIN output after partition pruning; Tom accepted the additional removal and confirmed the output change, while explaining that view display and pg_dump use parse trees and would not be affected #12 #13 #14 #17.
- The broader prevention discussion also explored generated deeply const types, C++ support, and comparing plan trees before and after execution, but these ideas remained proposals outside the attached fix #7 #15 #18 #19.
- Tom's final submission added EXPLAIN reference-name assignment for the original first target relation even when startup pruning removes it, removed both executor assignments, and enabled verbose regression output to cover the behavior; he now favored avoiding backpatches because the observable EXPLAIN change outweighed the known consequences of the mutation #20.
- The thread ends with that revised submission, which subsequently landed with identical code and tests and an expanded commit message as d376ab570e; the commit credits Andres and Tom and explicitly limits the fix to development toward PostgreSQL 18 to preserve existing branches' EXPLAIN output #20.