@@ -1183,22 +1183,19 @@ slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
11831183}
11841184
11851185/*
1186- * slot_getsomeattrs
1187- * This function forces the entries of the slot's Datum/isnull
1188- * arrays to be valid at least up through the attnum'th entry.
1186+ * slot_getsomeattrs_int - workhorse for slot_getsomeattrs()
11891187 */
11901188void
1191- slot_getsomeattrs (TupleTableSlot * slot , int attnum )
1189+ slot_getsomeattrs_int (TupleTableSlot * slot , int attnum )
11921190{
11931191 HeapTuple tuple ;
11941192 int attno ;
11951193
1196- /* Quick out if we have 'em all already */
1197- if (slot -> tts_nvalid >= attnum )
1198- return ;
1194+ /* Check for caller errors */
1195+ Assert (slot -> tts_nvalid < attnum ); /* slot_getsomeattr checked */
1196+ Assert ( attnum > 0 ) ;
11991197
1200- /* Check for caller error */
1201- if (attnum <= 0 || attnum > slot -> tts_tupleDescriptor -> natts )
1198+ if (unlikely (attnum > slot -> tts_tupleDescriptor -> natts ))
12021199 elog (ERROR , "invalid attribute number %d" , attnum );
12031200
12041201 /*
@@ -1209,9 +1206,7 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
12091206 if (tuple == NULL ) /* internal error */
12101207 elog (ERROR , "cannot extract attribute from empty tuple slot" );
12111208
1212- /*
1213- * load up any slots available from physical tuple
1214- */
1209+ /* Fetch as many attributes as possible from the underlying tuple. */
12151210 attno = HeapTupleHeaderGetNatts (tuple -> t_data );
12161211 attno = Min (attno , attnum );
12171212
@@ -1220,13 +1215,14 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
12201215 attno = slot -> tts_nvalid ;
12211216
12221217 /*
1223- * If tuple doesn't have all the atts indicated by attnum, read the rest
1224- * as NULLs or missing values
1218+ * If the underlying tuple doesn't have enough attributes, tuple descriptor
1219+ * must have the missing attributes.
12251220 */
1226- if (attno < attnum )
1227- slot_getmissingattrs (slot , attno , attnum );
1228-
1229- slot -> tts_nvalid = attnum ;
1221+ if (unlikely (slot -> tts_nvalid < attnum ))
1222+ {
1223+ slot_getmissingattrs (slot , slot -> tts_nvalid , attnum );
1224+ slot -> tts_nvalid = attnum ;
1225+ }
12301226}
12311227
12321228/* ----------------------------------------------------------------
0 commit comments