Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d906f1

Browse files
committed
Move generic slot support functions from heaptuple.c into execTuples.c.
heaptuple.c was never a particular good fit for slot_getattr(),slot_getsomeattrs() and slot_getmissingattrs(), but in upcomingchanges slots will be made more abstract (allowing slots that containdifferent types of tuples), making it clearly the wrong place.Note that slot_deform_tuple() remains in it's current place, as itclearly deals with a HeapTuple. getmissingattrs() also remains, butit's less clear that that's correct - but execTuples.c wouldn't be theright place.Author: Ashutosh Bapat.Discussion:https://postgr.es/m/20180220224318.gw4oe5jadhpmcdnm@alap3.anarazel.de
1 parente73ca79 commit9d906f1

File tree

4 files changed

+201
-189
lines changed

4 files changed

+201
-189
lines changed

‎src/backend/access/common/heaptuple.c

Lines changed: 2 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
/*
8181
* Return the missing value of an attribute, or NULL if there isn't one.
8282
*/
83-
staticDatum
83+
Datum
8484
getmissingattr(TupleDesctupleDesc,
8585
intattnum,bool*isnull)
8686
{
@@ -111,43 +111,6 @@ getmissingattr(TupleDesc tupleDesc,
111111
returnPointerGetDatum(NULL);
112112
}
113113

114-
/*
115-
* Fill in missing values for a TupleTableSlot.
116-
*
117-
* This is only exposed because it's needed for JIT compiled tuple
118-
* deforming. That exception aside, there should be no callers outside of this
119-
* file.
120-
*/
121-
void
122-
slot_getmissingattrs(TupleTableSlot*slot,intstartAttNum,intlastAttNum)
123-
{
124-
AttrMissing*attrmiss=NULL;
125-
intmissattnum;
126-
127-
if (slot->tts_tupleDescriptor->constr)
128-
attrmiss=slot->tts_tupleDescriptor->constr->missing;
129-
130-
if (!attrmiss)
131-
{
132-
/* no missing values array at all, so just fill everything in as NULL */
133-
memset(slot->tts_values+startAttNum,0,
134-
(lastAttNum-startAttNum)*sizeof(Datum));
135-
memset(slot->tts_isnull+startAttNum,1,
136-
(lastAttNum-startAttNum)*sizeof(bool));
137-
}
138-
else
139-
{
140-
/* if there is a missing values array we must process them one by one */
141-
for (missattnum=startAttNum;
142-
missattnum<lastAttNum;
143-
missattnum++)
144-
{
145-
slot->tts_values[missattnum]=attrmiss[missattnum].am_value;
146-
slot->tts_isnull[missattnum]= !attrmiss[missattnum].am_present;
147-
}
148-
}
149-
}
150-
151114
/*
152115
* heap_compute_data_size
153116
*Determine size of the data area of a tuple to be constructed
@@ -1398,7 +1361,7 @@ heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
13981361
*re-computing information about previously extracted attributes.
13991362
*slot->tts_nvalid is the number of attributes already extracted.
14001363
*/
1401-
staticvoid
1364+
void
14021365
slot_deform_tuple(TupleTableSlot*slot,intnatts)
14031366
{
14041367
HeapTupletuple=slot->tts_tuple;
@@ -1492,153 +1455,6 @@ slot_deform_tuple(TupleTableSlot *slot, int natts)
14921455
slot->tts_slow=slow;
14931456
}
14941457

1495-
/*
1496-
* slot_getattr
1497-
*This function fetches an attribute of the slot's current tuple.
1498-
*It is functionally equivalent to heap_getattr, but fetches of
1499-
*multiple attributes of the same tuple will be optimized better,
1500-
*because we avoid O(N^2) behavior from multiple calls of
1501-
*nocachegetattr(), even when attcacheoff isn't usable.
1502-
*
1503-
*A difference from raw heap_getattr is that attnums beyond the
1504-
*slot's tupdesc's last attribute will be considered NULL even
1505-
*when the physical tuple is longer than the tupdesc.
1506-
*/
1507-
Datum
1508-
slot_getattr(TupleTableSlot*slot,intattnum,bool*isnull)
1509-
{
1510-
HeapTupletuple=slot->tts_tuple;
1511-
TupleDesctupleDesc=slot->tts_tupleDescriptor;
1512-
HeapTupleHeadertup;
1513-
1514-
/*
1515-
* system attributes are handled by heap_getsysattr
1516-
*/
1517-
if (attnum <=0)
1518-
{
1519-
if (tuple==NULL)/* internal error */
1520-
elog(ERROR,"cannot extract system attribute from virtual tuple");
1521-
if (tuple==&(slot->tts_minhdr))/* internal error */
1522-
elog(ERROR,"cannot extract system attribute from minimal tuple");
1523-
returnheap_getsysattr(tuple,attnum,tupleDesc,isnull);
1524-
}
1525-
1526-
/*
1527-
* fast path if desired attribute already cached
1528-
*/
1529-
if (attnum <=slot->tts_nvalid)
1530-
{
1531-
*isnull=slot->tts_isnull[attnum-1];
1532-
returnslot->tts_values[attnum-1];
1533-
}
1534-
1535-
/*
1536-
* return NULL if attnum is out of range according to the tupdesc
1537-
*/
1538-
if (attnum>tupleDesc->natts)
1539-
{
1540-
*isnull= true;
1541-
return (Datum)0;
1542-
}
1543-
1544-
/*
1545-
* otherwise we had better have a physical tuple (tts_nvalid should equal
1546-
* natts in all virtual-tuple cases)
1547-
*/
1548-
if (tuple==NULL)/* internal error */
1549-
elog(ERROR,"cannot extract attribute from empty tuple slot");
1550-
1551-
/*
1552-
* return NULL or missing value if attnum is out of range according to the
1553-
* tuple
1554-
*
1555-
* (We have to check this separately because of various inheritance and
1556-
* table-alteration scenarios: the tuple could be either longer or shorter
1557-
* than the tupdesc.)
1558-
*/
1559-
tup=tuple->t_data;
1560-
if (attnum>HeapTupleHeaderGetNatts(tup))
1561-
returngetmissingattr(slot->tts_tupleDescriptor,attnum,isnull);
1562-
1563-
/*
1564-
* check if target attribute is null: no point in groveling through tuple
1565-
*/
1566-
if (HeapTupleHasNulls(tuple)&&att_isnull(attnum-1,tup->t_bits))
1567-
{
1568-
*isnull= true;
1569-
return (Datum)0;
1570-
}
1571-
1572-
/*
1573-
* If the attribute's column has been dropped, we force a NULL result.
1574-
* This case should not happen in normal use, but it could happen if we
1575-
* are executing a plan cached before the column was dropped.
1576-
*/
1577-
if (TupleDescAttr(tupleDesc,attnum-1)->attisdropped)
1578-
{
1579-
*isnull= true;
1580-
return (Datum)0;
1581-
}
1582-
1583-
/*
1584-
* Extract the attribute, along with any preceding attributes.
1585-
*/
1586-
slot_deform_tuple(slot,attnum);
1587-
1588-
/*
1589-
* The result is acquired from tts_values array.
1590-
*/
1591-
*isnull=slot->tts_isnull[attnum-1];
1592-
returnslot->tts_values[attnum-1];
1593-
}
1594-
1595-
/*
1596-
* slot_getsomeattrs
1597-
*This function forces the entries of the slot's Datum/isnull
1598-
*arrays to be valid at least up through the attnum'th entry.
1599-
*/
1600-
void
1601-
slot_getsomeattrs(TupleTableSlot*slot,intattnum)
1602-
{
1603-
HeapTupletuple;
1604-
intattno;
1605-
1606-
/* Quick out if we have 'em all already */
1607-
if (slot->tts_nvalid >=attnum)
1608-
return;
1609-
1610-
/* Check for caller error */
1611-
if (attnum <=0||attnum>slot->tts_tupleDescriptor->natts)
1612-
elog(ERROR,"invalid attribute number %d",attnum);
1613-
1614-
/*
1615-
* otherwise we had better have a physical tuple (tts_nvalid should equal
1616-
* natts in all virtual-tuple cases)
1617-
*/
1618-
tuple=slot->tts_tuple;
1619-
if (tuple==NULL)/* internal error */
1620-
elog(ERROR,"cannot extract attribute from empty tuple slot");
1621-
1622-
/*
1623-
* load up any slots available from physical tuple
1624-
*/
1625-
attno=HeapTupleHeaderGetNatts(tuple->t_data);
1626-
attno=Min(attno,attnum);
1627-
1628-
slot_deform_tuple(slot,attno);
1629-
1630-
attno=slot->tts_nvalid;
1631-
1632-
/*
1633-
* If tuple doesn't have all the atts indicated by attnum, read the rest
1634-
* as NULLs or missing values
1635-
*/
1636-
if (attno<attnum)
1637-
slot_getmissingattrs(slot,attno,attnum);
1638-
1639-
slot->tts_nvalid=attnum;
1640-
}
1641-
16421458
/*
16431459
* slot_attisnull
16441460
*Detect whether an attribute of the slot is null, without

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp