Fix FOR PORTION OF for inheritance children ExecForPortionOfLeftovers() assumed that any result relation with ri_RootResultRelInfo should reinsert temporal leftovers through the root relation. That is correct for partitioned tables, where tuple routing is needed, but it is wrong for plain inheritance.
When UPDATE/DELETE FOR PORTION OF is run on an inheritance parent and a child row is split, the leftover rows must be inserted back into the child relation. Reinserting through the parent can lose child-only columns and place the leftover rows in the wrong relation. Fix this by distinguishing partitioned-table routing from plain inheritance. For partitioned tables, keep using the root leftover slot and insert through the root relation. For plain inheritance children, use a leftover slot matching the child relation and insert directly into the child. Also keep translating the application-time column attno for child relations, so multiple-inheritance cases with different attribute numbers are handled correctly. Added an ExecInitForPortionOf function to set up the ForPortionOfState for each child table, which keeps most of these decisions localized instead of spread out through ExecForPortionOfLeftovers. Incidentally clarified a comment about the rangetype stored in ForPortionOfState. Add regression tests for UPDATE and DELETE FOR PORTION OF on inheritance children, including a multiple-inheritance case where the range column has a different attnum in the parent and child. Author: jian he <[email protected]> Co-authored-by: Chao Li <[email protected]> Reviewed-by: Paul A. Jungwirth <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/4245F94D-84F1-4E05-BF81-C458A6CF9901%40gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/7d13b03a2e677b78047cf537e519166dcbafa117 Modified Files -------------- src/backend/executor/nodeModifyTable.c | 158 ++++++++++++++++++--------- src/include/nodes/execnodes.h | 3 +- src/test/regress/expected/for_portion_of.out | 158 +++++++++++++++++++++++++++ src/test/regress/sql/for_portion_of.sql | 85 ++++++++++++++ 4 files changed, 353 insertions(+), 51 deletions(-)
