{
            CheckOpSlotCompatibility(op, innerslot);
 
-           /* XXX: worthwhile to check tts_nvalid inline first? */
            slot_getsomeattrs(innerslot, op->d.fetch.last_var);
 
            EEO_NEXT();
 
 }
 
 /*
- * slot_getsomeattrs
- *     This function forces the entries of the slot's Datum/isnull
- *     arrays to be valid at least up through the attnum'th entry.
+ * slot_getsomeattrs_int - workhorse for slot_getsomeattrs()
  */
 void
-slot_getsomeattrs(TupleTableSlot *slot, int attnum)
+slot_getsomeattrs_int(TupleTableSlot *slot, int attnum)
 {
    HeapTuple   tuple;
    int         attno;
 
-   /* Quick out if we have 'em all already */
-   if (slot->tts_nvalid >= attnum)
-       return;
+   /* Check for caller errors */
+   Assert(slot->tts_nvalid < attnum); /* slot_getsomeattr checked */
+   Assert(attnum > 0);
 
-   /* Check for caller error */
-   if (attnum <= 0 || attnum > slot->tts_tupleDescriptor->natts)
+   if (unlikely(attnum > slot->tts_tupleDescriptor->natts))
        elog(ERROR, "invalid attribute number %d", attnum);
 
    /*
    if (tuple == NULL)          /* internal error */
        elog(ERROR, "cannot extract attribute from empty tuple slot");
 
-   /*
-    * load up any slots available from physical tuple
-    */
+   /* Fetch as many attributes as possible from the underlying tuple. */
    attno = HeapTupleHeaderGetNatts(tuple->t_data);
    attno = Min(attno, attnum);
 
    attno = slot->tts_nvalid;
 
    /*
-    * If tuple doesn't have all the atts indicated by attnum, read the rest
-    * as NULLs or missing values
+    * If the underlying tuple doesn't have enough attributes, tuple descriptor
+    * must have the missing attributes.
     */
-   if (attno < attnum)
-       slot_getmissingattrs(slot, attno, attnum);
-
-   slot->tts_nvalid = attnum;
+   if (unlikely(slot->tts_nvalid < attnum))
+   {
+       slot_getmissingattrs(slot, slot->tts_nvalid, attnum);
+       slot->tts_nvalid = attnum;
+   }
 }
 
 /* ----------------------------------------------------------------
 
 LLVMValueRef AttributeTemplate;
 LLVMValueRef FuncStrlen;
 LLVMValueRef FuncVarsizeAny;
-LLVMValueRef FuncSlotGetsomeattrs;
+LLVMValueRef FuncSlotGetsomeattrsInt;
 LLVMValueRef FuncSlotGetmissingattrs;
 LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
 LLVMValueRef FuncExecEvalArrayRefSubscript;
    AttributeTemplate = LLVMGetNamedFunction(mod, "AttributeTemplate");
    FuncStrlen = LLVMGetNamedFunction(mod, "strlen");
    FuncVarsizeAny = LLVMGetNamedFunction(mod, "varsize_any");
-   FuncSlotGetsomeattrs = LLVMGetNamedFunction(mod, "slot_getsomeattrs");
+   FuncSlotGetsomeattrsInt = LLVMGetNamedFunction(mod, "slot_getsomeattrs_int");
    FuncSlotGetmissingattrs = LLVMGetNamedFunction(mod, "slot_getmissingattrs");
    FuncMakeExpandedObjectReadOnlyInternal = LLVMGetNamedFunction(mod, "MakeExpandedObjectReadOnlyInternal");
    FuncExecEvalArrayRefSubscript = LLVMGetNamedFunction(mod, "ExecEvalArrayRefSubscript");
 
                        params[1] = l_int32_const(op->d.fetch.last_var);
 
                        LLVMBuildCall(b,
-                                     llvm_get_decl(mod, FuncSlotGetsomeattrs),
+                                     llvm_get_decl(mod, FuncSlotGetsomeattrsInt),
                                      params, lengthof(params), "");
                    }
 
 
 {
    strlen,
    varsize_any,
-   slot_getsomeattrs,
+   slot_getsomeattrs_int,
    slot_getmissingattrs,
    MakeExpandedObjectReadOnlyInternal,
    ExecEvalArrayRefSubscript,
 
                     int lastAttNum);
 extern Datum slot_getattr(TupleTableSlot *slot, int attnum,
             bool *isnull);
-extern void slot_getsomeattrs(TupleTableSlot *slot, int attnum);
 
 /* in access/common/heaptuple.c */
 extern bool slot_attisnull(TupleTableSlot *slot, int attnum);
                Datum *value, bool *isnull);
 extern Datum getmissingattr(TupleDesc tupleDesc,
               int attnum, bool *isnull);
+extern void slot_getsomeattrs_int(TupleTableSlot *slot, int attnum);
 
 #ifndef FRONTEND
 
+/*
+ * This function forces the entries of the slot's Datum/isnull arrays to be
+ * valid at least up through the attnum'th entry.
+ */
+static inline void
+slot_getsomeattrs(TupleTableSlot *slot, int attnum)
+{
+   if (slot->tts_nvalid < attnum)
+       slot_getsomeattrs_int(slot, attnum);
+}
+
 /*
  * slot_getallattrs
  *     This function forces all the entries of the slot's Datum/isnull
 
 extern LLVMValueRef AttributeTemplate;
 extern LLVMValueRef FuncStrlen;
 extern LLVMValueRef FuncVarsizeAny;
-extern LLVMValueRef FuncSlotGetsomeattrs;
 extern LLVMValueRef FuncSlotGetmissingattrs;
+extern LLVMValueRef FuncSlotGetsomeattrsInt;
 extern LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal;
 extern LLVMValueRef FuncExecEvalArrayRefSubscript;
 extern LLVMValueRef FuncExecEvalSysVar;