diff --git a/src/backend/executor/nodeForeignscan.c b/src/backend/executor/nodeForeignscan.c index 9cc5345..728db14 100644 --- a/src/backend/executor/nodeForeignscan.c +++ b/src/backend/executor/nodeForeignscan.c @@ -22,6 +22,8 @@ */ #include "postgres.h" +#include "access/transam.h" +#include "access/htup_details.h" #include "executor/executor.h" #include "executor/nodeForeignscan.h" #include "foreign/fdwapi.h" @@ -58,8 +60,21 @@ ForeignNext(ForeignScanState *node) */ if (plan->fsSystemCol && !TupIsNull(slot)) { + bool was_virtual_tuple = (slot->tts_tuple == NULL); HeapTuple tup = ExecMaterializeSlot(slot); + if (was_virtual_tuple) + { + /* + * ExecMaterializeSlot fills the tuple header as a + * DatumTupleFields if the slot was a virtual tuple, but a + * physical one is needed here. So rewrite the tuple header as + * HeapTupleFirelds. + */ + HeapTupleHeaderSetXmin(tup->t_data, FrozenTransactionId); + HeapTupleHeaderSetXmax(tup->t_data, InvalidTransactionId); + HeapTupleHeaderSetCmin(tup->t_data, FirstCommandId); + } tup->t_tableOid = RelationGetRelid(node->ss.ss_currentRelation); }