Skip to content

Commit c3437fb

Browse files
committed
Expand comments and add an assertion in nodeModifyTable.c.
Most comments concern RELKIND_VIEW. One addresses the ExecUpdate() "tupleid" parameter. A later commit will rely on these facts, but they hold already. Back-patch to v12 (all supported versions), the plan for that commit. Reviewed (in an earlier version) by Robert Haas. Discussion: https://postgr.es/m/20240512232923.aa.nmisch@google.com
1 parent 65aae93 commit c3437fb

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
* rowtype, but we might still find that different plans are appropriate
2929
* for different child relations.
3030
*
31+
* The relation to modify can be an ordinary table, a view having an
32+
* INSTEAD OF trigger, or a foreign table. Earlier processing already
33+
* pointed ModifyTable to the underlying relations of any automatically
34+
* updatable view not using an INSTEAD OF trigger, so code here can
35+
* assume it won't have one as a modification target. This node does
36+
* process ri_WithCheckOptions, which may have expressions from those
37+
* automatically updatable views.
38+
*
3139
* If the query specifies RETURNING, then the ModifyTable returns a
3240
* RETURNING tuple after completing each row insert, update, or delete.
3341
* It must be called again to continue the operation. Without RETURNING,
@@ -812,8 +820,8 @@ ExecInsert(ModifyTableState *mtstate,
812820
* index modifications are needed.
813821
*
814822
* When deleting from a table, tupleid identifies the tuple to
815-
* delete and oldtuple is NULL. When deleting from a view,
816-
* oldtuple is passed to the INSTEAD OF triggers and identifies
823+
* delete and oldtuple is NULL. When deleting through a view
824+
* INSTEAD OF trigger, oldtuple is passed to the triggers and identifies
817825
* what to delete, and tupleid is invalid. When deleting from a
818826
* foreign table, tupleid is invalid; the FDW has to figure out
819827
* which row to delete using data from the planSlot. oldtuple is
@@ -1178,15 +1186,17 @@ ldelete:;
11781186
* which corrupts your database..
11791187
*
11801188
* When updating a table, tupleid identifies the tuple to
1181-
* update and oldtuple is NULL. When updating a view, oldtuple
1182-
* is passed to the INSTEAD OF triggers and identifies what to
1189+
* update and oldtuple is NULL. When updating through a view INSTEAD OF
1190+
* trigger, oldtuple is passed to the triggers and identifies what to
11831191
* update, and tupleid is invalid. When updating a foreign table,
11841192
* tupleid is invalid; the FDW has to figure out which row to
11851193
* update using data from the planSlot. oldtuple is passed to
11861194
* foreign table triggers; it is NULL when the foreign table has
11871195
* no relevant triggers.
11881196
*
1189-
* Returns RETURNING result if any, otherwise NULL.
1197+
* Returns RETURNING result if any, otherwise NULL. On exit, if tupleid
1198+
* had identified the tuple to update, it will identify the tuple
1199+
* actually updated after EvalPlanQual.
11901200
* ----------------------------------------------------------------
11911201
*/
11921202
static TupleTableSlot *
@@ -2337,8 +2347,8 @@ ExecModifyTable(PlanState *pstate)
23372347
* to set t_tableOid. Quite separately from this, the FDW may
23382348
* fetch its own junk attrs to identify the row.
23392349
*
2340-
* Other relevant relkinds, currently limited to views, always
2341-
* have a wholerow attribute.
2350+
* Other relevant relkinds, currently limited to views having
2351+
* INSTEAD OF triggers, always have a wholerow attribute.
23422352
*/
23432353
else if (AttributeNumberIsValid(junkfilter->jf_junkAttNo))
23442354
{

0 commit comments

Comments
 (0)