model-writtenrun 9210 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Michael Paquier opened the thread by proposing to move BulkInsertState helpers out of heap-specific code so custom table access methods would not need heapam.h; Andres Freund preferred allocating bulk-insert state inside each access method, and Michael acknowledged that a deeper redesign could be preferable #1 #2 #3.
- Michael explored combining state cleanup with finish_bulk_insert and adding a pin-release callback, while Robert Haas advocated reusable heap-style support and outlined an operations-table abstraction; Andres preferred routing those operations through the table access method itself #5 #7 #8.
- Robert's observation that COPY could create multiple bulk-insert states but finish only the main table exposed a missing per-partition callback; Andres confirmed this was a bug for custom access methods even though heap did not currently suffer from it #7 #8.
- David Rowley's first patch called table_finish_bulk_insert whenever a partition's multi-insert buffer was cleaned up, potentially finishing the same partition repeatedly, and moved final buffer cleanup later in CopyFrom #10.
- Andres warned that repeated finish calls could incur expensive fsyncs, prompting David to replace buffer-based finishing with a callback over the executor's routed partitions at COPY completion; David kept PartitionTupleRouting private and avoided adding work to its normal cleanup path #13 #14.
- Michael objected to the extra callback layer, and David ultimately deferred the optimization because heap was unaffected, landing the original patch as 4de60244e2 with an additional guard restricting the target-table finish call to bulk inserts #15 #17 #18.
- The first landing was reverted by f5db56fc4d pending further work; Michael still favored the original structure, and David planned to repair it despite its repeated-call inefficiency #19 #20.
- David landed the repaired original approach as f7c830f1ab, moving buffer cleanup before partition and executor teardown and removing the separate target-table finish call; he announced that cleanup now occurred in the correct order #21.
- Michael subsequently examined the second landing and approved its logic, but this review occurred after the commit; Andres renewed the performance discussion and proposed either reporting first partition use or exposing the relations already tracked by tuple routing #22 #23.
- David preferred exposing routed relations to avoid changing ExecFindPartition's signature or making COPY maintain another list; Andres accepted that direction, while whether to include the optimization in PostgreSQL 12 remained unresolved #24 #25 #26 #27.
- The final attachment adds ExecGetRoutedToRelations and moves finish calls to COPY completion on top of the landed fix, retaining the earlier function signatures; the correctness fix has landed, but this optimization remains proposed and the original BulkInsertState abstraction work has no attached implementation in the thread #28.