/* ---------------- *nocache_index_getattr * *Thisgetscalledfromindex_getattr()macro,andonlyincases *wherewecan'tusecacheoffsetandthevalueisnotnull. * *Thiscachesattributeoffsetsintheattributedescriptor. * *Analternativewaytospeedthingsupwouldbetocacheoffsets *withthetuple,butthatseemsmoredifficultunlessyoutake *thestoragehitofactuallyputtingthoseoffsetsintothe *tupleyousendtodisk.Yuck. * *Thisschemewillbeslightlyslowerthanthat,butshould *performwellforquerieswhichhitlarge#'softuples.After *youcachetheoffsetsonce,examiningalltheothertuplesusing *thesameattributedescriptorwillgomuchquicker.-cim5/4/91 *----------------
*/
Datum
nocache_index_getattr(IndexTuple tup, int attnum,
TupleDesc tupleDesc)
{ char *tp; /* ptr to data part of tuple */
bits8 *bp = NULL; /* ptr to null bitmap in tuple */ bool slow = false; /* do we have to walk attrs? */ int data_off; /* tuple data offset */ int off; /* current offset within data */
if (IndexTupleHasNulls(tup))
{ /* *there'sanullsomewhereinthetuple * *checktoseeifdesiredattisnull
*/
/* XXX "knows" t_bits are just after fixed tuple header! */
bp = (bits8 *) ((char *) tup + sizeof(IndexTupleData));
/* *Nowchecktoseeifanyprecedingbitsarenull...
*/
{ int byte = attnum >> 3; int finalbit = attnum & 0x07;
/* check for nulls "before" final bit of last byte */ if ((~bp[byte]) & ((1 << finalbit) - 1))
slow = true; else
{ /* check for nulls in any "earlier" bytes */ int i;
for (i = 0; i < byte; i++)
{ if (bp[i] != 0xFF)
{
slow = true; break;
}
}
}
}
}
tp = (char *) tup + data_off;
if (!slow)
{
CompactAttribute *att;
/* *Ifwegethere,therearenonullsuptoandincludingthetarget *attribute.Ifwehaveacachedoffset,wecanuseit.
*/
att = TupleDescCompactAttr(tupleDesc, attnum); if (att->attcacheoff >= 0) return fetchatt(att, tp + att->attcacheoff);
/* *Otherwise,checkfornon-fixed-lengthattrsuptoandincluding *target.Iftherearen'tany,it'ssafetocheaplyinitializethe *cachedoffsetsfortheseattrs.
*/ if (IndexTupleHasVarwidths(tup))
{ int j;
off = TupleDescCompactAttr(tupleDesc, attnum)->attcacheoff;
} else
{ bool usecache = true; int i;
/* *NowweknowthatwehavetowalkthetupleCAREFULLY.Butwestill *mightbeabletocachesomeoffsetsfornexttime. * *Note-Thisloopisalittletricky.Foreachnon-nullattribute, *wehavetofirstaccountforalignmentpaddingbeforetheattr, *thenadvanceovertheattrbasedonitslength.Nullshaveno *storageandnoalignmentpaddingeither.Wecanuse/set *attcacheoffuntilwereacheitheranulloravar-widthattribute.
*/
off = 0; for (i = 0;; i++) /* loop exit is at "break" */
{
CompactAttribute *att = TupleDescCompactAttr(tupleDesc, i);
if (IndexTupleHasNulls(tup) && att_isnull(i, bp))
{
usecache = false; continue; /* this cannot be the target att */
}
/* If we know the next offset, we can skip the rest */ if (usecache && att->attcacheoff >= 0)
off = att->attcacheoff; elseif (att->attlen == -1)
{ /* *Wecanonlycachetheoffsetforavarlenaattributeifthe *offsetisalreadysuitablyaligned,sothattherewouldbe *nopadbytesinanycase:thentheoffsetwillbevalidfor *eitheranalignedorunalignedvalue.
*/ if (usecache &&
off == att_nominal_alignby(off, att->attalignby))
att->attcacheoff = off; else
{
off = att_pointer_alignby(off, att->attalignby, -1,
tp + off);
usecache = false;
}
} else
{ /* not varlena, so safe to use att_nominal_alignby */
off = att_nominal_alignby(off, att->attalignby);
if (usecache)
att->attcacheoff = off;
}
if (i == attnum) break;
off = att_addlength_pointer(off, att->attlen, tp + off);
/* *ConvertanindextupleintoDatum/isnullarrays, *withoutassuminganyspecificlayoutoftheindextupleheader. * *Callermustsupplypointertodataarea,pointertonullsbitmap *(whichcanbeNULLif!hasnulls),andhasnullsflag.
*/ void
index_deform_tuple_internal(TupleDesc tupleDescriptor,
Datum *values, bool *isnull, char *tp, bits8 *bp, int hasnulls)
{ int natts = tupleDescriptor->natts; /* number of atts to extract */ int attnum; int off = 0; /* offset in tuple data */ bool slow = false; /* can we use/set attcacheoff? */
/* Assert to protect callers who allocate fixed-size arrays */
Assert(natts <= INDEX_MAX_KEYS);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.