Skip to content

Commit 88ebd62

Browse files
committed
Deduplicate code between slot_getallattrs() and slot_getsomeattrs().
Code in slot_getallattrs() is the same as if slot_getsomeattrs() is called with number of attributes specified in the tuple descriptor. Implement it that way instead of duplicating the code between those two functions. This is part of a patchseries abstracting TupleTableSlots so they can store arbitrary forms of tuples, but is a nice enough cleanup on its own. Author: Ashutosh Bapat Reviewed-By: Andres Freund Discussion: https://postgr.es/m/20180220224318.gw4oe5jadhpmcdnm@alap3.anarazel.de
1 parent a40631a commit 88ebd62

File tree

2 files changed

+12
-46
lines changed

2 files changed

+12
-46
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,51 +1601,6 @@ slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
16011601
return slot->tts_values[attnum - 1];
16021602
}
16031603

1604-
/*
1605-
* slot_getallattrs
1606-
* This function forces all the entries of the slot's Datum/isnull
1607-
* arrays to be valid. The caller may then extract data directly
1608-
* from those arrays instead of using slot_getattr.
1609-
*/
1610-
void
1611-
slot_getallattrs(TupleTableSlot *slot)
1612-
{
1613-
int tdesc_natts = slot->tts_tupleDescriptor->natts;
1614-
int attnum;
1615-
HeapTuple tuple;
1616-
1617-
/* Quick out if we have 'em all already */
1618-
if (slot->tts_nvalid == tdesc_natts)
1619-
return;
1620-
1621-
/*
1622-
* otherwise we had better have a physical tuple (tts_nvalid should equal
1623-
* natts in all virtual-tuple cases)
1624-
*/
1625-
tuple = slot->tts_tuple;
1626-
if (tuple == NULL) /* internal error */
1627-
elog(ERROR, "cannot extract attribute from empty tuple slot");
1628-
1629-
/*
1630-
* load up any slots available from physical tuple
1631-
*/
1632-
attnum = HeapTupleHeaderGetNatts(tuple->t_data);
1633-
attnum = Min(attnum, tdesc_natts);
1634-
1635-
slot_deform_tuple(slot, attnum);
1636-
1637-
attnum = slot->tts_nvalid;
1638-
1639-
/*
1640-
* If tuple doesn't have all the atts indicated by tupleDesc, read the
1641-
* rest as NULLS or missing values.
1642-
*/
1643-
if (attnum < tdesc_natts)
1644-
slot_getmissingattrs(slot, attnum, tdesc_natts);
1645-
1646-
slot->tts_nvalid = tdesc_natts;
1647-
}
1648-
16491604
/*
16501605
* slot_getsomeattrs
16511606
* This function forces the entries of the slot's Datum/isnull

src/include/executor/tuptable.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,22 @@ extern TupleTableSlot *ExecCopySlot(TupleTableSlot *dstslot,
174174

175175
/* in access/common/heaptuple.c */
176176
extern Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull);
177-
extern void slot_getallattrs(TupleTableSlot *slot);
178177
extern void slot_getsomeattrs(TupleTableSlot *slot, int attnum);
179178
extern bool slot_attisnull(TupleTableSlot *slot, int attnum);
180179
extern bool slot_getsysattr(TupleTableSlot *slot, int attnum,
181180
Datum *value, bool *isnull);
182181
extern void slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum);
183182

183+
/*
184+
* slot_getallattrs
185+
* This function forces all the entries of the slot's Datum/isnull
186+
* arrays to be valid. The caller may then extract data directly
187+
* from those arrays instead of using slot_getattr.
188+
*/
189+
static inline void
190+
slot_getallattrs(TupleTableSlot *slot)
191+
{
192+
slot_getsomeattrs(slot, slot->tts_tupleDescriptor->natts);
193+
}
194+
184195
#endif /* TUPTABLE_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy