1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-02 11:44:50 +03:00

When modifying a foreign table, initialize tableoid field properly.

Failure to do this can cause AFTER ROW triggers or RETURNING expressions
that reference this field to misbehave.

Etsuro Fujita, reviewed by Thom Brown
This commit is contained in:
Robert Haas 2016-02-04 21:15:57 -05:00
parent 3676136ffc
commit 453d40817c

View File

@ -308,6 +308,12 @@ ExecInsert(ModifyTableState *mtstate,
/* FDW might have changed tuple */ /* FDW might have changed tuple */
tuple = ExecMaterializeSlot(slot); 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; newId = InvalidOid;
} }
else else
@ -561,6 +567,8 @@ ExecDelete(ItemPointer tupleid,
} }
else if (resultRelInfo->ri_FdwRoutine) else if (resultRelInfo->ri_FdwRoutine)
{ {
HeapTuple tuple;
/* /*
* delete from foreign table: let the FDW do it * delete from foreign table: let the FDW do it
* *
@ -579,6 +587,15 @@ ExecDelete(ItemPointer tupleid,
if (slot == NULL) /* "do nothing" */ if (slot == NULL) /* "do nothing" */
return NULL; 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 else
{ {
@ -838,6 +855,12 @@ ExecUpdate(ItemPointer tupleid,
/* FDW might have changed tuple */ /* FDW might have changed tuple */
tuple = ExecMaterializeSlot(slot); 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 else
{ {