Clean up code to resolve the "root target relation" in nodeModifyTable.c
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 19 Oct 2020 11:11:44 +0000 (14:11 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 19 Oct 2020 11:42:40 +0000 (14:42 +0300)
commitf49b85d783f6781138f33bbe5f6e98da86907d84
treea8b056023c829f7db9ca2711366f8258102ca832
parent26ec6b5948a73d0e07ed9435ee4554594acdf34f
Clean up code to resolve the "root target relation" in nodeModifyTable.c

When executing DDL on a partitioned table or on a table with inheritance
children, statement-level triggers must be fired against the table given
in the original statement. The code to look that up was a bit messy and
duplicative. Commit 501ed02cf6 added a helper function,
getASTriggerResultRelInfo() (later renamed to getTargetResultRelInfo())
for it, but for some reason it was only used when firing AFTER STATEMENT
triggers and the code to fire BEFORE STATEMENT triggers duplicated the
logic.

Determine the target relation in ExecInitModifyTable(), and set it always
in ModifyTableState. Code that used to call getTargetResultRelInfo() can
now use ModifyTableState->rootResultRelInfo directly.

Discussion: https://www.postgresql.org/message-id/CA%2BHiwqFViT47Zbr_ASBejiK7iDG8%3DQ1swQ-tjM6caRPQ67pT%3Dw%40mail.gmail.com
src/backend/executor/nodeModifyTable.c
src/include/nodes/execnodes.h