Skip to content

Commit 1f3294c

Browse files
committed
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
1 parent 411e2b0 commit 1f3294c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/backend/executor/nodeModifyTable.c

+23
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ ExecInsert(TupleTableSlot *slot,
242242
/* FDW might have changed tuple */
243243
tuple = ExecMaterializeSlot(slot);
244244

245+
/*
246+
* AFTER ROW Triggers or RETURNING expressions might reference the
247+
* tableoid column, so initialize t_tableOid before evaluating them.
248+
*/
249+
tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
250+
245251
newId = InvalidOid;
246252
}
247253
else
@@ -364,6 +370,8 @@ ExecDelete(ItemPointer tupleid,
364370
}
365371
else if (resultRelInfo->ri_FdwRoutine)
366372
{
373+
HeapTuple tuple;
374+
367375
/*
368376
* delete from foreign table: let the FDW do it
369377
*
@@ -382,6 +390,15 @@ ExecDelete(ItemPointer tupleid,
382390

383391
if (slot == NULL) /* "do nothing" */
384392
return NULL;
393+
394+
/*
395+
* RETURNING expressions might reference the tableoid column, so
396+
* initialize t_tableOid before evaluating them.
397+
*/
398+
if (slot->tts_isempty)
399+
ExecStoreAllNullTuple(slot);
400+
tuple = ExecMaterializeSlot(slot);
401+
tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
385402
}
386403
else
387404
{
@@ -641,6 +658,12 @@ ExecUpdate(ItemPointer tupleid,
641658

642659
/* FDW might have changed tuple */
643660
tuple = ExecMaterializeSlot(slot);
661+
662+
/*
663+
* AFTER ROW Triggers or RETURNING expressions might reference the
664+
* tableoid column, so initialize t_tableOid before evaluating them.
665+
*/
666+
tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
644667
}
645668
else
646669
{

0 commit comments

Comments
 (0)