Skip to content

Commit 9418d79

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 f8003e0 commit 9418d79

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ ExecInsert(ModifyTableState *mtstate,
308308
/* FDW might have changed tuple */
309309
tuple = ExecMaterializeSlot(slot);
310310

311+
/*
312+
* AFTER ROW Triggers or RETURNING expressions might reference the
313+
* tableoid column, so initialize t_tableOid before evaluating them.
314+
*/
315+
tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
316+
311317
newId = InvalidOid;
312318
}
313319
else
@@ -561,6 +567,8 @@ ExecDelete(ItemPointer tupleid,
561567
}
562568
else if (resultRelInfo->ri_FdwRoutine)
563569
{
570+
HeapTuple tuple;
571+
564572
/*
565573
* delete from foreign table: let the FDW do it
566574
*
@@ -579,6 +587,15 @@ ExecDelete(ItemPointer tupleid,
579587

580588
if (slot == NULL) /* "do nothing" */
581589
return NULL;
590+
591+
/*
592+
* RETURNING expressions might reference the tableoid column, so
593+
* initialize t_tableOid before evaluating them.
594+
*/
595+
if (slot->tts_isempty)
596+
ExecStoreAllNullTuple(slot);
597+
tuple = ExecMaterializeSlot(slot);
598+
tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
582599
}
583600
else
584601
{
@@ -838,6 +855,12 @@ ExecUpdate(ItemPointer tupleid,
838855

839856
/* FDW might have changed tuple */
840857
tuple = ExecMaterializeSlot(slot);
858+
859+
/*
860+
* AFTER ROW Triggers or RETURNING expressions might reference the
861+
* tableoid column, so initialize t_tableOid before evaluating them.
862+
*/
863+
tuple->t_tableOid = RelationGetRelid(resultRelationDesc);
841864
}
842865
else
843866
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy