model-writtenrun 2441 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Robins Tharakan reported a MERGE crash after the partition-pruning optimization, and Tender Wang traced it to pruning every target partition, leaving no initialized result relation or merge actions #1 #2.
- David Rowley proposed initializing the expression context before checking for an empty action list, but Tender Wang showed that this avoided the crash while silently skipping an insert that succeeded with pruning disabled and on PostgreSQL 17.1 #4 #6 #9.
- Dean Rasheed explained that MERGE action selection and partition routing both require at least one resultRelInfo entry, recommending retention of one leaf relation instead of the more invasive alternative of teaching those paths to use the root relation #16.
- Amit Langote implemented locking and retaining the first result relation, and Tender Wang endorsed the initial patch and supplied a regression-test query #18 #19.
- Dean Rasheed found that retaining the first relation in the statement-wide list failed for multiple ModifyTable nodes, and Tender Wang supplied an UPDATE-with-CTE variant exposing the same error #20 #21.
- Dean Rasheed reworked the fix to retain a fallback relation locally in each ModifyTable node, permit opening pruned result relations, hide the fallback from EXPLAIN, correct assertions, and add tests; Tender Wang tested it successfully and requested a matching API-comment update #22 #23.
- Amit Langote rejected acquiring these locks during node initialization because cached-plan invalidation must be handled before executor state is partially initialized, and added firstResultRels planner metadata so ExecDoInitialPruning() could acquire the locks early while retaining Dean's supporting changes #24.
- After discussing how initialization differs from locking partitions during tuple routing, Dean Rasheed accepted early locking and supplied a revision removing duplicated fallback initialization and improving names and comments #26 #27 #28.
- Amit Langote and Dean Rasheed deferred richer per-ModifyTable relation metadata that could avoid unnecessary fallback locks, judging the optimization insufficiently worthwhile, and finalized wording explaining that the fallback is initialized only when all result relations are pruned #29 #30 #31.
- Amit Langote committed #31 as 28317de723 with unchanged code and tests apart from rebase context and a lightly edited commit message, then confirmed the push; the correctness fix was complete, with only the optional locking optimization deferred #32.