When modifying a foreign table, initialize tableoid field properly.
authorRobert Haas
Fri, 5 Feb 2016 02:15:57 +0000 (21:15 -0500)
committerRobert Haas
Fri, 5 Feb 2016 02:15:57 +0000 (21:15 -0500)
Failure to do this can cause AFTER ROW triggers or RETURNING expressions
that reference this field to misbehave.

Etsuro Fujita, reviewed by Thom Brown

src/backend/executor/nodeModifyTable.c

index 8ac60477fb87900ea3c45cea9678473781a01cd8..9fb2ea177756a1300e30f42887e6566866d4e686 100644 (file)
@@ -242,6 +242,12 @@ ExecInsert(TupleTableSlot *slot,
        /* FDW might have changed tuple */
        tuple = ExecMaterializeSlot(slot);
 
+       /*
+        * AFTER ROW Triggers or RETURNING expressions might reference the
+        * tableoid column, so initialize t_tableOid before evaluating them.
+        */
+       tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
+
        newId = InvalidOid;
    }
    else
@@ -364,6 +370,8 @@ ExecDelete(ItemPointer tupleid,
    }
    else if (resultRelInfo->ri_FdwRoutine)
    {
+       HeapTuple   tuple;
+
        /*
         * delete from foreign table: let the FDW do it
         *
@@ -382,6 +390,15 @@ ExecDelete(ItemPointer tupleid,
 
        if (slot == NULL)       /* "do nothing" */
            return NULL;
+
+       /*
+        * RETURNING expressions might reference the tableoid column, so
+        * initialize t_tableOid before evaluating them.
+        */
+       if (slot->tts_isempty)
+           ExecStoreAllNullTuple(slot);
+       tuple = ExecMaterializeSlot(slot);
+       tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
    }
    else
    {
@@ -641,6 +658,12 @@ ExecUpdate(ItemPointer tupleid,
 
        /* FDW might have changed tuple */
        tuple = ExecMaterializeSlot(slot);
+
+       /*
+        * AFTER ROW Triggers or RETURNING expressions might reference the
+        * tableoid column, so initialize t_tableOid before evaluating them.
+        */
+       tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
    }
    else
    {