diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index 00dc339615..a4dc91869f 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -1044,7 +1044,7 @@ slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp,
 
 	for (; attnum < natts; attnum++)
 	{
-		Form_pg_attribute thisatt = TupleDescAttr(tupleDesc, attnum);
+		Form_pg_attribute thisatt;
 
 		if (hasnulls && att_isnull(attnum, bp))
 		{
@@ -1056,6 +1056,7 @@ slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp,
 
 		isnull[attnum] = false;
 
+		thisatt = TupleDescAttr(tupleDesc, attnum);
 		if (!slow && thisatt->attcacheoff >= 0)
 			off = thisatt->attcacheoff;
 		else if (thisatt->attlen == -1)
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index 5737f9f4eb..57598e79a7 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -591,7 +591,7 @@ tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
 	/* Check the tlist attributes */
 	for (attrno = 1; attrno <= numattrs; attrno++)
 	{
-		Form_pg_attribute att_tup = TupleDescAttr(tupdesc, attrno - 1);
+		Form_pg_attribute att_tup;
 		Var		   *var;
 
 		if (tlist_item == NULL)
@@ -604,6 +604,7 @@ tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
 		Assert(var->varlevelsup == 0);
 		if (var->varattno != attrno)
 			return false;		/* out of order */
+		att_tup = TupleDescAttr(tupdesc, attrno - 1);
 		if (att_tup->attisdropped)
 			return false;		/* table contains dropped columns */
 		if (att_tup->atthasmissing)
diff --git a/src/backend/executor/nodeTableFuncscan.c b/src/backend/executor/nodeTableFuncscan.c
index f483221bb8..9e28863d44 100644
--- a/src/backend/executor/nodeTableFuncscan.c
+++ b/src/backend/executor/nodeTableFuncscan.c
@@ -400,11 +400,10 @@ tfuncInitialize(TableFuncScanState *tstate, ExprContext *econtext, Datum doc)
 	tupdesc = tstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
 	foreach(lc1, tstate->colexprs)
 	{
-		char	   *colfilter;
-		Form_pg_attribute att = TupleDescAttr(tupdesc, colno);
-
 		if (colno != ordinalitycol)
 		{
+			char	   *colfilter;
+			Form_pg_attribute att = TupleDescAttr(tupdesc, colno);
 			ExprState  *colexpr = lfirst(lc1);
 
 			if (colexpr != NULL)
@@ -472,8 +471,6 @@ tfuncLoadRows(TableFuncScanState *tstate, ExprContext *econtext)
 		 */
 		for (colno = 0; colno < natts; colno++)
 		{
-			Form_pg_attribute att = TupleDescAttr(tupdesc, colno);
-
 			if (colno == ordinalitycol)
 			{
 				/* Fast path for ordinality column */
@@ -482,6 +479,7 @@ tfuncLoadRows(TableFuncScanState *tstate, ExprContext *econtext)
 			}
 			else
 			{
+				Form_pg_attribute att = TupleDescAttr(tupdesc, colno);
 				bool		isnull;
 
 				values[colno] = routine->GetValue(tstate,
