mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Inline fastgetattr and others so data access does not use function
calls.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* heaptuple.c--
|
||||
* This file contains heap tuple accessor and mutator routines, as well
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.30 1998/01/07 21:00:40 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.31 1998/01/31 04:38:02 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* The old interface functions have been converted to macros
|
||||
@@ -32,6 +32,16 @@
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
/* Used by heap_getattr() macro, for speed */
|
||||
long heap_sysoffset[] = {
|
||||
/* Only the first one is pass-by-ref, and is handled specially in the macro */
|
||||
offsetof(HeapTupleData, t_ctid),
|
||||
offsetof(HeapTupleData, t_oid),
|
||||
offsetof(HeapTupleData, t_xmin),
|
||||
offsetof(HeapTupleData, t_cmin),
|
||||
offsetof(HeapTupleData, t_xmax),
|
||||
offsetof(HeapTupleData, t_cmax)
|
||||
};
|
||||
|
||||
/* this is so the sparcstation debugger works */
|
||||
|
||||
@@ -345,7 +355,7 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
|
||||
{
|
||||
switch (attnum)
|
||||
{
|
||||
case SelfItemPointerAttributeNumber:
|
||||
case SelfItemPointerAttributeNumber:
|
||||
return ((Datum) &tup->t_ctid);
|
||||
case ObjectIdAttributeNumber:
|
||||
return ((Datum) (long) tup->t_oid);
|
||||
@@ -364,10 +374,12 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* fastgetattr
|
||||
* nocachegetattr
|
||||
*
|
||||
* This is a newer version of fastgetattr which attempts to be
|
||||
* faster by caching attribute offsets in the attribute descriptor.
|
||||
* This only gets called from fastgetattr() macro, in cases where
|
||||
* we can't use a cacheoffset and the value is not null.
|
||||
*
|
||||
* This caches attribute offsets in the attribute descriptor.
|
||||
*
|
||||
* an alternate way to speed things up would be to cache offsets
|
||||
* with the tuple, but that seems more difficult unless you take
|
||||
@@ -381,7 +393,7 @@ heap_getsysattr(HeapTuple tup, Buffer b, int attnum)
|
||||
* ----------------
|
||||
*/
|
||||
Datum
|
||||
fastgetattr(HeapTuple tup,
|
||||
nocachegetattr(HeapTuple tup,
|
||||
int attnum,
|
||||
TupleDesc tupleDesc,
|
||||
bool *isnull)
|
||||
@@ -391,13 +403,15 @@ fastgetattr(HeapTuple tup,
|
||||
int slow; /* do we have to walk nulls? */
|
||||
AttributeTupleForm *att = tupleDesc->attrs;
|
||||
|
||||
/* ----------------
|
||||
* sanity checks
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
|
||||
#if IN_MACRO
|
||||
/* This is handled in the macro */
|
||||
Assert(attnum > 0);
|
||||
|
||||
if (isnull)
|
||||
*isnull = false;
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* Three cases:
|
||||
*
|
||||
@@ -407,12 +421,12 @@ fastgetattr(HeapTuple tup,
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
if (isnull)
|
||||
*isnull = false;
|
||||
|
||||
if (HeapTupleNoNulls(tup))
|
||||
{
|
||||
attnum--;
|
||||
|
||||
#if IN_MACRO
|
||||
/* This is handled in the macro */
|
||||
if (att[attnum]->attcacheoff > 0)
|
||||
{
|
||||
return (Datum)
|
||||
@@ -427,6 +441,7 @@ fastgetattr(HeapTuple tup,
|
||||
*/
|
||||
return ((Datum) fetchatt(&(att[0]), (char *) tup + tup->t_hoff));
|
||||
}
|
||||
#endif
|
||||
|
||||
tp = (char *) tup + tup->t_hoff;
|
||||
|
||||
@@ -449,12 +464,15 @@ fastgetattr(HeapTuple tup,
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
#if IN_MACRO
|
||||
/* This is handled in the macro */
|
||||
if (att_isnull(attnum, bp))
|
||||
{
|
||||
if (isnull)
|
||||
*isnull = true;
|
||||
return (Datum) NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* Now check to see if any preceeding bits are null...
|
||||
@@ -539,7 +557,7 @@ fastgetattr(HeapTuple tup,
|
||||
if (att[j]->attlen < sizeof(int32))
|
||||
{
|
||||
elog(ERROR,
|
||||
"fastgetattr: attribute %d has len %d",
|
||||
"nocachegetattr: attribute %d has len %d",
|
||||
j, att[j]->attlen);
|
||||
}
|
||||
if (att[j]->attalign == 'd')
|
||||
@@ -599,7 +617,7 @@ fastgetattr(HeapTuple tup,
|
||||
default:
|
||||
if (att[i]->attlen < sizeof(int32))
|
||||
elog(ERROR,
|
||||
"fastgetattr2: attribute %d has len %d",
|
||||
"nocachegetattr2: attribute %d has len %d",
|
||||
i, att[i]->attlen);
|
||||
if (att[i]->attalign == 'd')
|
||||
off = DOUBLEALIGN(off);
|
||||
@@ -657,7 +675,7 @@ fastgetattr(HeapTuple tup,
|
||||
break;
|
||||
default:
|
||||
if (att[attnum]->attlen < sizeof(int32))
|
||||
elog(ERROR, "fastgetattr3: attribute %d has len %d",
|
||||
elog(ERROR, "nocachegetattr3: attribute %d has len %d",
|
||||
attnum, att[attnum]->attlen);
|
||||
if (att[attnum]->attalign == 'd')
|
||||
off = DOUBLEALIGN(off);
|
||||
@@ -719,7 +737,6 @@ heap_deformtuple(HeapTuple tuple,
|
||||
bool isnull;
|
||||
|
||||
values[i] = heap_getattr(tuple,
|
||||
InvalidBuffer,
|
||||
i + 1,
|
||||
tdesc,
|
||||
&isnull);
|
||||
@@ -874,7 +891,6 @@ heap_modifytuple(HeapTuple tuple,
|
||||
{
|
||||
value[attoff] =
|
||||
heap_getattr(tuple,
|
||||
InvalidBuffer,
|
||||
AttrOffsetGetAttrNumber(attoff),
|
||||
RelationGetTupleDescriptor(relation),
|
||||
&isNull);
|
||||
@@ -959,3 +975,4 @@ heap_addheader(uint32 natts, /* max domain index */
|
||||
|
||||
return (tup);
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.22 1998/01/07 21:00:43 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.23 1998/01/31 04:38:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -26,11 +26,6 @@
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
static Size IndexInfoFindDataOffset(unsigned short t_info);
|
||||
static char *
|
||||
fastgetiattr(IndexTuple tup, int attnum,
|
||||
TupleDesc att, bool *isnull);
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* index_ tuple interface routines
|
||||
* ----------------------------------------------------------------
|
||||
@@ -117,10 +112,12 @@ index_formtuple(TupleDesc tupleDescriptor,
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* fastgetiattr
|
||||
* nocache_index_getattr
|
||||
*
|
||||
* This is a newer version of fastgetiattr which attempts to be
|
||||
* faster by caching attribute offsets in the attribute descriptor.
|
||||
* This gets called from index_getattr() macro, and only in cases
|
||||
* where we can't use cacheoffset and the value is not null.
|
||||
*
|
||||
* This caches attribute offsets in the attribute descriptor.
|
||||
*
|
||||
* an alternate way to speed things up would be to cache offsets
|
||||
* with the tuple, but that seems more difficult unless you take
|
||||
@@ -133,8 +130,8 @@ index_formtuple(TupleDesc tupleDescriptor,
|
||||
* the same attribute descriptor will go much quicker. -cim 5/4/91
|
||||
* ----------------
|
||||
*/
|
||||
static char *
|
||||
fastgetiattr(IndexTuple tup,
|
||||
Datum
|
||||
nocache_index_getattr(IndexTuple tup,
|
||||
int attnum,
|
||||
TupleDesc tupleDesc,
|
||||
bool *isnull)
|
||||
@@ -150,9 +147,6 @@ fastgetiattr(IndexTuple tup,
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
Assert(PointerIsValid(isnull));
|
||||
Assert(attnum > 0);
|
||||
|
||||
/* ----------------
|
||||
* Three cases:
|
||||
*
|
||||
@@ -162,27 +156,37 @@ fastgetiattr(IndexTuple tup,
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
#ifdef IN_MACRO
|
||||
/* This is handled in the macro */
|
||||
Assert(PointerIsValid(isnull));
|
||||
Assert(attnum > 0);
|
||||
|
||||
*isnull = false;
|
||||
#endif
|
||||
|
||||
data_off = IndexTupleHasMinHeader(tup) ? sizeof *tup :
|
||||
IndexInfoFindDataOffset(tup->t_info);
|
||||
|
||||
if (IndexTupleNoNulls(tup))
|
||||
{
|
||||
attnum--;
|
||||
|
||||
#ifdef IN_MACRO
|
||||
/* This is handled in the macro */
|
||||
|
||||
/* first attribute is always at position zero */
|
||||
|
||||
if (attnum == 1)
|
||||
{
|
||||
return (fetchatt(&(att[0]), (char *) tup + data_off));
|
||||
return (Datum) fetchatt(&(att[0]), (char *) tup + data_off);
|
||||
}
|
||||
attnum--;
|
||||
|
||||
if (att[attnum]->attcacheoff > 0)
|
||||
{
|
||||
return (fetchatt(&(att[attnum]),
|
||||
return (Datum) fetchatt(&(att[attnum]),
|
||||
(char *) tup + data_off +
|
||||
att[attnum]->attcacheoff));
|
||||
att[attnum]->attcacheoff);
|
||||
}
|
||||
#endif
|
||||
|
||||
tp = (char *) tup + data_off;
|
||||
|
||||
@@ -191,8 +195,6 @@ fastgetiattr(IndexTuple tup,
|
||||
else
|
||||
{ /* there's a null somewhere in the tuple */
|
||||
|
||||
bp = (char *) tup + sizeof(*tup); /* "knows" t_bits are
|
||||
* here! */
|
||||
slow = 0;
|
||||
/* ----------------
|
||||
* check to see if desired att is null
|
||||
@@ -200,13 +202,19 @@ fastgetiattr(IndexTuple tup,
|
||||
*/
|
||||
|
||||
attnum--;
|
||||
|
||||
bp = (char *) tup + sizeof(*tup); /* "knows" t_bits are
|
||||
* here! */
|
||||
#ifdef IN_MACRO
|
||||
/* This is handled in the macro */
|
||||
|
||||
if (att_isnull(attnum, bp))
|
||||
{
|
||||
if (att_isnull(attnum, bp))
|
||||
{
|
||||
*isnull = true;
|
||||
return NULL;
|
||||
}
|
||||
*isnull = true;
|
||||
return (Datum)NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* Now check to see if any preceeding bits are null...
|
||||
* ----------------
|
||||
@@ -251,8 +259,8 @@ fastgetiattr(IndexTuple tup,
|
||||
{
|
||||
if (att[attnum]->attcacheoff > 0)
|
||||
{
|
||||
return (fetchatt(&(att[attnum]),
|
||||
tp + att[attnum]->attcacheoff));
|
||||
return (Datum) fetchatt(&(att[attnum]),
|
||||
tp + att[attnum]->attcacheoff);
|
||||
}
|
||||
else if (!IndexTupleAllFixed(tup))
|
||||
{
|
||||
@@ -314,7 +322,7 @@ fastgetiattr(IndexTuple tup,
|
||||
off = (att[j]->attalign == 'd') ?
|
||||
DOUBLEALIGN(off) : LONGALIGN(off);
|
||||
else
|
||||
elog(ERROR, "fastgetiattr: attribute %d has len %d",
|
||||
elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
|
||||
j, att[j]->attlen);
|
||||
break;
|
||||
|
||||
@@ -324,8 +332,8 @@ fastgetiattr(IndexTuple tup,
|
||||
off += att[j]->attlen;
|
||||
}
|
||||
|
||||
return (fetchatt(&(att[attnum]),
|
||||
tp + att[attnum]->attcacheoff));
|
||||
return (Datum) fetchatt(&(att[attnum]),
|
||||
tp + att[attnum]->attcacheoff);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -382,7 +390,7 @@ fastgetiattr(IndexTuple tup,
|
||||
DOUBLEALIGN(off) + att[i]->attlen :
|
||||
LONGALIGN(off) + att[i]->attlen;
|
||||
else
|
||||
elog(ERROR, "fastgetiattr2: attribute %d has len %d",
|
||||
elog(ERROR, "nocache_index_getattr2: attribute %d has len %d",
|
||||
i, att[i]->attlen);
|
||||
|
||||
break;
|
||||
@@ -391,7 +399,7 @@ fastgetiattr(IndexTuple tup,
|
||||
|
||||
/*
|
||||
* I don't know why this code was missed here! I've got it from
|
||||
* heaptuple.c:fastgetattr(). - vadim 06/12/97
|
||||
* heaptuple.c:nocachegetattr(). - vadim 06/12/97
|
||||
*/
|
||||
switch (att[attnum]->attlen)
|
||||
{
|
||||
@@ -409,7 +417,7 @@ fastgetiattr(IndexTuple tup,
|
||||
break;
|
||||
default:
|
||||
if (att[attnum]->attlen < sizeof(int32))
|
||||
elog(ERROR, "fastgetattr3: attribute %d has len %d",
|
||||
elog(ERROR, "nocache_index_getattr: attribute %d has len %d",
|
||||
attnum, att[attnum]->attlen);
|
||||
if (att[attnum]->attalign == 'd')
|
||||
off = DOUBLEALIGN(off);
|
||||
@@ -418,26 +426,10 @@ fastgetiattr(IndexTuple tup,
|
||||
break;
|
||||
}
|
||||
|
||||
return (fetchatt(&att[attnum], tp + off));
|
||||
return (Datum) fetchatt(&att[attnum], tp + off);
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* index_getattr
|
||||
* ----------------
|
||||
*/
|
||||
Datum
|
||||
index_getattr(IndexTuple tuple,
|
||||
AttrNumber attNum,
|
||||
TupleDesc tupDesc,
|
||||
bool *isNullOutP)
|
||||
{
|
||||
Assert(attNum > 0);
|
||||
|
||||
return (Datum)
|
||||
fastgetiattr(tuple, attNum, tupDesc, isNullOutP);
|
||||
}
|
||||
|
||||
RetrieveIndexResult
|
||||
FormRetrieveIndexResult(ItemPointer indexItemPointer,
|
||||
ItemPointer heapItemPointer)
|
||||
@@ -455,29 +447,6 @@ FormRetrieveIndexResult(ItemPointer indexItemPointer,
|
||||
return (result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Takes an infomask as argument (primarily because this needs to be usable
|
||||
* at index_formtuple time so enough space is allocated).
|
||||
*
|
||||
* Change me if adding an attribute to IndexTuples!!!!!!!!!!!
|
||||
*/
|
||||
static Size
|
||||
IndexInfoFindDataOffset(unsigned short t_info)
|
||||
{
|
||||
if (!(t_info & INDEX_NULL_MASK))
|
||||
return ((Size) sizeof(IndexTupleData));
|
||||
else
|
||||
{
|
||||
Size size = sizeof(IndexTupleData);
|
||||
|
||||
if (t_info & INDEX_NULL_MASK)
|
||||
{
|
||||
size += sizeof(IndexAttributeBitMapData);
|
||||
}
|
||||
return DOUBLEALIGN(size); /* be conservative */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copies source into target. If *target == NULL, we palloc space; otherwise
|
||||
* we assume we have space that is already palloc'ed.
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.22 1998/01/07 21:00:44 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.23 1998/01/31 04:38:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -97,7 +97,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
|
||||
{
|
||||
i++; /* heap_getattr is a macro, so no
|
||||
* increment */
|
||||
attr = heap_getattr(tuple, InvalidBuffer, i, typeinfo, &isnull);
|
||||
attr = heap_getattr(tuple, i, typeinfo, &isnull);
|
||||
if (!isnull)
|
||||
j |= k;
|
||||
k >>= 1;
|
||||
@@ -117,7 +117,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
|
||||
*/
|
||||
for (i = 0; i < tuple->t_natts; ++i)
|
||||
{
|
||||
attr = heap_getattr(tuple, InvalidBuffer, i + 1, typeinfo, &isnull);
|
||||
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
|
||||
typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
|
||||
|
||||
if (!isnull && OidIsValid(typoutput))
|
||||
@@ -183,7 +183,7 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo)
|
||||
|
||||
for (i = 0; i < tuple->t_natts; ++i)
|
||||
{
|
||||
attr = heap_getattr(tuple, InvalidBuffer, i + 1, typeinfo, &isnull);
|
||||
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
|
||||
typoutput = typtoout((Oid) typeinfo->attrs[i]->atttypid);
|
||||
|
||||
if (!isnull && OidIsValid(typoutput))
|
||||
@@ -231,7 +231,7 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
|
||||
{
|
||||
i++; /* heap_getattr is a macro, so no
|
||||
* increment */
|
||||
attr = heap_getattr(tuple, InvalidBuffer, i, typeinfo, &isnull);
|
||||
attr = heap_getattr(tuple, i, typeinfo, &isnull);
|
||||
if (!isnull)
|
||||
j |= k;
|
||||
k >>= 1;
|
||||
@@ -256,7 +256,7 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
|
||||
{
|
||||
int32 len = typeinfo->attrs[i]->attlen;
|
||||
|
||||
attr = heap_getattr(tuple, InvalidBuffer, i + 1, typeinfo, &isnull);
|
||||
attr = heap_getattr(tuple, i + 1, typeinfo, &isnull);
|
||||
if (!isnull)
|
||||
{
|
||||
/* # of bytes, and opaque data */
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.19 1998/01/07 21:01:42 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.20 1998/01/31 04:38:06 momjian Exp $
|
||||
*
|
||||
* INTERFACE ROUTINES
|
||||
* index_open - open an index relation by relationId
|
||||
@@ -386,7 +386,6 @@ GetIndexValue(HeapTuple tuple,
|
||||
for (i = 0; i < FIgetnArgs(fInfo); i++)
|
||||
{
|
||||
attData[i] = heap_getattr(tuple,
|
||||
buffer,
|
||||
attrNums[i],
|
||||
hTupDesc,
|
||||
attNull);
|
||||
@@ -400,7 +399,7 @@ GetIndexValue(HeapTuple tuple,
|
||||
}
|
||||
else
|
||||
{
|
||||
returnVal = heap_getattr(tuple, buffer, attrNums[attOff],
|
||||
returnVal = heap_getattr(tuple, attrNums[attOff],
|
||||
hTupDesc, attNull);
|
||||
}
|
||||
return returnVal;
|
||||
|
Reference in New Issue
Block a user