diff --git a/src/backend/executor/nodeForeignscan.c b/src/backend/executor/nodeForeignscan.c
index 9cc5345..59dc5f4 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, although a
+			 * physical one is needed by the callers. So rewrite the tuple
+			 * header as a sane HeapTupleFields.
+			 */
+			HeapTupleHeaderSetXmin(tup->t_data, FrozenTransactionId);
+			HeapTupleHeaderSetXmax(tup->t_data, InvalidTransactionId);
+			HeapTupleHeaderSetCmin(tup->t_data, FirstCommandId);
+		}
 		tup->t_tableOid = RelationGetRelid(node->ss.ss_currentRelation);
 	}
 
