diff --git a/contrib/pgstattuple/pgstatapprox.c b/contrib/pgstattuple/pgstatapprox.c
index a59ff4e9d4..26afe55c01 100644
--- a/contrib/pgstattuple/pgstatapprox.c
+++ b/contrib/pgstattuple/pgstatapprox.c
@@ -78,6 +78,7 @@ statapprox_heap(Relation rel, output_type *stat)
 		OffsetNumber offnum,
 					maxoff;
 		Size		freespace;
+		HeapTupleData tuple;
 
 		CHECK_FOR_INTERRUPTS();
 
@@ -118,12 +119,15 @@ statapprox_heap(Relation rel, output_type *stat)
 		 */
 		maxoff = PageGetMaxOffsetNumber(page);
 
+		/* block and tableOid is the same for all tuples, set it once outside the loop */
+		ItemPointerSetBlockNumber(&tuple.t_self, blkno);
+		tuple.t_tableOid = RelationGetRelid(rel);
+
 		for (offnum = FirstOffsetNumber;
 			 offnum <= maxoff;
 			 offnum = OffsetNumberNext(offnum))
 		{
 			ItemId		itemid;
-			HeapTupleData tuple;
 
 			itemid = PageGetItemId(page, offnum);
 
@@ -135,11 +139,9 @@ statapprox_heap(Relation rel, output_type *stat)
 
 			Assert(ItemIdIsNormal(itemid));
 
-			ItemPointerSet(&(tuple.t_self), blkno, offnum);
-
 			tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid);
 			tuple.t_len = ItemIdGetLength(itemid);
-			tuple.t_tableOid = RelationGetRelid(rel);
+			ItemPointerSetOffsetNumber(&tuple.t_self, offnum);
 
 			/*
 			 * We follow VACUUM's lead in counting INSERT_IN_PROGRESS tuples
