PostgreSQL Source Code git master
Loading...
Searching...
No Matches
itup.h File Reference
#include "access/tupdesc.h"
#include "access/tupmacs.h"
#include "storage/bufpage.h"
#include "storage/itemptr.h"
Include dependency graph for itup.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  IndexTupleData
 
struct  IndexAttributeBitMapData
 

Macros

#define INDEX_SIZE_MASK   0x1FFF
 
#define INDEX_AM_RESERVED_BIT
 
#define INDEX_VAR_MASK   0x4000
 
#define INDEX_NULL_MASK   0x8000
 
#define MaxIndexTuplesPerPage
 

Typedefs

typedef struct IndexTupleData IndexTupleData
 
typedef IndexTupleDataIndexTuple
 
typedef struct IndexAttributeBitMapData IndexAttributeBitMapData
 
typedef IndexAttributeBitMapDataIndexAttributeBitMap
 

Functions

static Size IndexTupleSize (const IndexTupleData *itup)
 
static bool IndexTupleHasNulls (const IndexTupleData *itup)
 
static bool IndexTupleHasVarwidths (const IndexTupleData *itup)
 
IndexTuple index_form_tuple (TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
 
IndexTuple index_form_tuple_context (TupleDesc tupleDescriptor, const Datum *values, const bool *isnull, MemoryContext context)
 
Datum nocache_index_getattr (IndexTuple tup, int attnum, TupleDesc tupleDesc)
 
void index_deform_tuple (IndexTuple tup, TupleDesc tupleDescriptor, Datum *values, bool *isnull)
 
void index_deform_tuple_internal (TupleDesc tupleDescriptor, Datum *values, bool *isnull, char *tp, bits8 *bp, int hasnulls)
 
IndexTuple CopyIndexTuple (IndexTuple source)
 
IndexTuple index_truncate_tuple (TupleDesc sourceDescriptor, IndexTuple source, int leavenatts)
 
static Size IndexInfoFindDataOffset (unsigned short t_info)
 
static Datum index_getattr (IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
 

Macro Definition Documentation

◆ INDEX_AM_RESERVED_BIT

#define INDEX_AM_RESERVED_BIT
Value:
0x2000 /* reserved for index-AM specific
* usage */

Definition at line 66 of file itup.h.

73{
74 return (itup->t_info & INDEX_SIZE_MASK);
75}
76
77static inline bool
79{
80 return itup->t_info & INDEX_NULL_MASK;
81}
82
83static inline bool
85{
86 return itup->t_info & INDEX_VAR_MASK;
87}
88
89
90/* routines in indextuple.c */
92 const Datum *values, const bool *isnull);
94 const Datum *values, const bool *isnull,
95 MemoryContext context);
99 Datum *values, bool *isnull);
101 Datum *values, bool *isnull,
102 char *tp, bits8 *bp, int hasnulls);
106
107
108/*
109 * Takes an infomask as argument (primarily because this needs to be usable
110 * at index_form_tuple time so enough space is allocated).
111 */
112static inline Size
113IndexInfoFindDataOffset(unsigned short t_info)
114{
115 if (!(t_info & INDEX_NULL_MASK))
116 return MAXALIGN(sizeof(IndexTupleData));
117 else
118 return MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData));
119}
120
121#ifndef FRONTEND
122
123/* ----------------
124 * index_getattr
125 *
126 * This gets called many times, so we macro the cacheable and NULL
127 * lookups, and call nocache_index_getattr() for the rest.
128 *
129 * ----------------
130 */
131static inline Datum
133{
134 Assert(isnull);
135 Assert(attnum > 0);
136
137 *isnull = false;
138
140 {
142
143 if (attr->attcacheoff >= 0)
144 {
145 return fetchatt(attr,
146 (char *) tup + IndexInfoFindDataOffset(tup->t_info) +
147 attr->attcacheoff);
148 }
149 else
151 }
152 else
153 {
154 if (att_isnull(attnum - 1, (bits8 *) tup + sizeof(IndexTupleData)))
155 {
156 *isnull = true;
157 return (Datum) 0;
158 }
159 else
161 }
162}
163
164#endif
165
166/*
167 * MaxIndexTuplesPerPage is an upper bound on the number of tuples that can
168 * fit on one index page. An index tuple must have either data or a null
169 * bitmap, so we can safely assume it's at least 1 byte bigger than a bare
170 * IndexTupleData struct. We arrive at the divisor because each tuple
171 * must be maxaligned, and it must have an associated line pointer.
172 *
173 * To be index-type-independent, this does not account for any special space
174 * on the page, and is thus conservative.
175 *
176 * Note: in btree non-leaf pages, the first tuple has no key (it's implicitly
177 * minus infinity), thus breaking the "at least 1 byte bigger" assumption.
178 * On such a page, N tuples could take one MAXALIGN quantum less space than
179 * estimated here, seemingly allowing one more tuple than estimated here.
180 * But such a page always has at least MAXALIGN special space, so we're safe.
181 */
182#define MaxIndexTuplesPerPage \
183 ((int) ((BLCKSZ - SizeOfPageHeaderData) / \
184 (MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData))))
185
186#endif /* ITUP_H */
static Datum values[MAXATTR]
Definition bootstrap.c:188
#define MAXALIGN(LEN)
Definition c.h:898
#define Assert(condition)
Definition c.h:945
uint8 bits8
Definition c.h:625
size_t Size
Definition c.h:691
#define INDEX_VAR_MASK
Definition itup.h:67
void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition indextuple.c:364
IndexTuple index_truncate_tuple(TupleDesc sourceDescriptor, IndexTuple source, int leavenatts)
Definition indextuple.c:508
#define INDEX_NULL_MASK
Definition itup.h:68
static bool IndexTupleHasVarwidths(const IndexTupleData *itup)
Definition itup.h:83
IndexTuple CopyIndexTuple(IndexTuple source)
Definition indextuple.c:479
static bool IndexTupleHasNulls(const IndexTupleData *itup)
Definition itup.h:77
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition itup.h:131
void index_deform_tuple_internal(TupleDesc tupleDescriptor, Datum *values, bool *isnull, char *tp, bits8 *bp, int hasnulls)
Definition indextuple.c:387
IndexTuple index_form_tuple_context(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull, MemoryContext context)
Definition indextuple.c:65
Datum nocache_index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc)
Definition indextuple.c:229
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition indextuple.c:44
static Size IndexInfoFindDataOffset(unsigned short t_info)
Definition itup.h:112
#define INDEX_SIZE_MASK
Definition itup.h:65
int16 attnum
static rewind_source * source
Definition pg_rewind.c:89
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
int16 attcacheoff
Definition tupdesc.h:70
unsigned short t_info
Definition itup.h:49
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:195
static bool att_isnull(int ATT, const bits8 *BITS)
Definition tupmacs.h:28
#define fetchatt(A, T)
Definition tupmacs.h:102

◆ INDEX_NULL_MASK

#define INDEX_NULL_MASK   0x8000

Definition at line 68 of file itup.h.

◆ INDEX_SIZE_MASK

#define INDEX_SIZE_MASK   0x1FFF

Definition at line 65 of file itup.h.

◆ INDEX_VAR_MASK

#define INDEX_VAR_MASK   0x4000

Definition at line 67 of file itup.h.

◆ MaxIndexTuplesPerPage

#define MaxIndexTuplesPerPage
Value:
(MAXALIGN(sizeof(IndexTupleData) + 1) + sizeof(ItemIdData))))
#define SizeOfPageHeaderData
Definition bufpage.h:242

Definition at line 181 of file itup.h.

Typedef Documentation

◆ IndexAttributeBitMap

◆ IndexAttributeBitMapData

◆ IndexTuple

Definition at line 53 of file itup.h.

◆ IndexTupleData

Function Documentation

◆ CopyIndexTuple()

IndexTuple CopyIndexTuple ( IndexTuple  source)
extern

Definition at line 479 of file indextuple.c.

480{
481 IndexTuple result;
482 Size size;
483
484 size = IndexTupleSize(source);
485 result = (IndexTuple) palloc(size);
486 memcpy(result, source, size);
487 return result;
488}
IndexTupleData * IndexTuple
Definition itup.h:53
static Size IndexTupleSize(const IndexTupleData *itup)
Definition itup.h:71
void * palloc(Size size)
Definition mcxt.c:1387

References fb(), IndexTupleSize(), palloc(), and source.

Referenced by _bt_buildadd(), _bt_insert_parent(), _bt_insertonpg(), _bt_load(), _bt_newlevel(), _bt_pagedel(), _bt_swap_posting(), _hash_splitbucket(), _hash_squeezebucket(), btree_xlog_insert(), btree_xlog_split(), gin_check_parent_keys_consistency(), gin_refind_parent(), gistformdownlink(), and index_truncate_tuple().

◆ index_deform_tuple()

void index_deform_tuple ( IndexTuple  tup,
TupleDesc  tupleDescriptor,
Datum values,
bool isnull 
)
extern

Definition at line 364 of file indextuple.c.

366{
367 char *tp; /* ptr to tuple data */
368 bits8 *bp; /* ptr to null bitmap in tuple */
369
370 /* XXX "knows" t_bits are just after fixed tuple header! */
371 bp = (bits8 *) ((char *) tup + sizeof(IndexTupleData));
372
373 tp = (char *) tup + IndexInfoFindDataOffset(tup->t_info);
374
377}
void index_deform_tuple_internal(TupleDesc tupleDescriptor, Datum *values, bool *isnull, char *tp, bits8 *bp, int hasnulls)
Definition indextuple.c:387

References fb(), index_deform_tuple_internal(), IndexInfoFindDataOffset(), IndexTupleHasNulls(), and values.

Referenced by _bt_check_unique(), comparetup_index_btree_tiebreak(), get_actual_variable_endpoint(), gist_page_items(), index_truncate_tuple(), and StoreIndexTuple().

◆ index_deform_tuple_internal()

void index_deform_tuple_internal ( TupleDesc  tupleDescriptor,
Datum values,
bool isnull,
char tp,
bits8 bp,
int  hasnulls 
)
extern

Definition at line 387 of file indextuple.c.

390{
392 int natts = tupleDescriptor->natts; /* number of atts to extract */
393 int attnum = 0;
394 uint32 off = 0; /* offset in tuple data */
396 int firstNullAttr;
397
398 /* Assert to protect callers who allocate fixed-size arrays */
399 Assert(natts <= INDEX_MAX_KEYS);
400
401 /* Did someone forget to call TupleDescFinalize()? */
402 Assert(tupleDescriptor->firstNonCachedOffsetAttr >= 0);
403
404 firstNonCacheOffsetAttr = Min(tupleDescriptor->firstNonCachedOffsetAttr, natts);
405
406 if (hasnulls)
407 {
410 }
411 else
412 firstNullAttr = natts;
413
415 {
416#ifdef USE_ASSERT_CHECKING
417 /* In Assert enabled builds, verify attcacheoff is correct */
418 off = 0;
419#endif
420
421 do
422 {
423 isnull[attnum] = false;
425
426#ifdef USE_ASSERT_CHECKING
427 off = att_nominal_alignby(off, cattr->attalignby);
428 Assert(off == cattr->attcacheoff);
429 off += cattr->attlen;
430#endif
431
432 values[attnum] = fetch_att_noerr(tp + cattr->attcacheoff, cattr->attbyval,
433 cattr->attlen);
434 } while (++attnum < firstNonCacheOffsetAttr);
435
436 off = cattr->attcacheoff + cattr->attlen;
437 }
438
439 for (; attnum < firstNullAttr; attnum++)
440 {
441 isnull[attnum] = false;
443
444 /* align 'off', fetch the datum, and increment off beyond the datum */
446 &off,
447 cattr->attbyval,
448 cattr->attlen,
449 cattr->attalignby);
450 }
451
452 for (; attnum < natts; attnum++)
453 {
455
456 if (att_isnull(attnum, bp))
457 {
458 values[attnum] = (Datum) 0;
459 isnull[attnum] = true;
460 continue;
461 }
462
463 isnull[attnum] = false;
465
466 /* align 'off', fetch the attr's value, and increment off beyond it */
468 &off,
469 cattr->attbyval,
470 cattr->attlen,
471 cattr->attalignby);
472 }
473}
#define Min(x, y)
Definition c.h:1093
uint32_t uint32
Definition c.h:618
#define INDEX_MAX_KEYS
#define att_nominal_alignby(cur_offset, attalignby)
Definition tupmacs.h:411
static int first_null_attr(const bits8 *bits, int natts)
Definition tupmacs.h:244
static Datum align_fetch_then_add(const char *tupptr, uint32 *off, bool attbyval, int attlen, uint8 attalignby)
Definition tupmacs.h:172
static Datum fetch_att_noerr(const void *T, bool attbyval, int attlen)
Definition tupmacs.h:137

References align_fetch_then_add(), Assert, att_isnull(), att_nominal_alignby, attnum, fb(), fetch_att_noerr(), first_null_attr(), INDEX_MAX_KEYS, Min, TupleDescCompactAttr(), and values.

Referenced by index_deform_tuple(), and spgDeformLeafTuple().

◆ index_form_tuple()

IndexTuple index_form_tuple ( TupleDesc  tupleDescriptor,
const Datum values,
const bool isnull 
)
extern

Definition at line 44 of file indextuple.c.

47{
50}
IndexTuple index_form_tuple_context(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull, MemoryContext context)
Definition indextuple.c:65
MemoryContext CurrentMemoryContext
Definition mcxt.c:160

References CurrentMemoryContext, fb(), index_form_tuple_context(), and values.

Referenced by bt_normalize_tuple(), bt_tuple_present_callback(), btinsert(), GinFormTuple(), gistFormTuple(), hashbuildCallback(), hashinsert(), and index_truncate_tuple().

◆ index_form_tuple_context()

IndexTuple index_form_tuple_context ( TupleDesc  tupleDescriptor,
const Datum values,
const bool isnull,
MemoryContext  context 
)
extern

Definition at line 65 of file indextuple.c.

69{
70 char *tp; /* tuple pointer */
71 IndexTuple tuple; /* return tuple */
72 Size size,
74 hoff;
75 int i;
76 unsigned short infomask = 0;
77 bool hasnull = false;
78 uint16 tupmask = 0;
80
81#ifdef TOAST_INDEX_HACK
84#endif
85
89 errmsg("number of index columns (%d) exceeds limit (%d)",
91
92#ifdef TOAST_INDEX_HACK
93 for (i = 0; i < numberOfAttributes; i++)
94 {
96
98 untoasted_free[i] = false;
99
100 /* Do nothing if value is NULL or not of varlena type */
101 if (isnull[i] || att->attlen != -1)
102 continue;
103
104 /*
105 * If value is stored EXTERNAL, must fetch it so we are not depending
106 * on outside storage. This should be improved someday.
107 */
109 {
113 untoasted_free[i] = true;
114 }
115
116 /*
117 * If value is above size target, and is of a compressible datatype,
118 * try to compress it in-line.
119 */
122 (att->attstorage == TYPSTORAGE_EXTENDED ||
123 att->attstorage == TYPSTORAGE_MAIN))
124 {
126
128 att->attcompression);
129
131 {
132 /* successful compression */
133 if (untoasted_free[i])
136 untoasted_free[i] = true;
137 }
138 }
139 }
140#endif
141
142 for (i = 0; i < numberOfAttributes; i++)
143 {
144 if (isnull[i])
145 {
146 hasnull = true;
147 break;
148 }
149 }
150
151 if (hasnull)
153
155#ifdef TOAST_INDEX_HACK
157 untoasted_values, isnull);
158#else
160 values, isnull);
161#endif
162 size = hoff + data_size;
163 size = MAXALIGN(size); /* be conservative */
164
165 tp = (char *) MemoryContextAllocZero(context, size);
166 tuple = (IndexTuple) tp;
167
171#else
172 values,
173#endif
174 isnull,
175 tp + hoff,
176 data_size,
177 &tupmask,
178 (hasnull ? (bits8 *) tp + sizeof(IndexTupleData) : NULL));
179
180#ifdef TOAST_INDEX_HACK
181 for (i = 0; i < numberOfAttributes; i++)
182 {
183 if (untoasted_free[i])
185 }
186#endif
187
188 /*
189 * We do this because heap_fill_tuple wants to initialize a "tupmask"
190 * which is used for HeapTuples, but we want an indextuple infomask. The
191 * only relevant info is the "has variable attributes" field. We have
192 * already set the hasnull bit above.
193 */
196
197 /* Also assert we got rid of external attributes */
198#ifdef TOAST_INDEX_HACK
200#endif
201
202 /*
203 * Here we make sure that the size will fit in the field reserved for it
204 * in t_info.
205 */
206 if ((size & INDEX_SIZE_MASK) != size)
209 errmsg("index row requires %zu bytes, maximum size is %zu",
210 size, (Size) INDEX_SIZE_MASK)));
211
212 infomask |= size;
213
214 /*
215 * initialize metadata
216 */
217 tuple->t_info = infomask;
218 return tuple;
219}
uint16_t uint16
Definition c.h:617
varlena * detoast_external_attr(varlena *attr)
Definition detoast.c:45
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
#define TOAST_INDEX_TARGET
Definition heaptoast.h:68
Size heap_compute_data_size(TupleDesc tupleDesc, const Datum *values, const bool *isnull)
Definition heaptuple.c:219
void heap_fill_tuple(TupleDesc tupleDesc, const Datum *values, const bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit)
Definition heaptuple.c:401
#define HEAP_HASVARWIDTH
#define HEAP_HASEXTERNAL
#define TOAST_INDEX_HACK
Definition indextuple.c:29
int i
Definition isn.c:77
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1266
void pfree(void *pointer)
Definition mcxt.c:1616
static char * errmsg
FormData_pg_attribute * Form_pg_attribute
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332
Definition c.h:778
Datum toast_compress_datum(Datum value, char cmethod)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178
static bool VARATT_IS_EXTENDED(const void *PTR)
Definition varatt.h:410
static bool VARATT_IS_EXTERNAL(const void *PTR)
Definition varatt.h:354
static Size VARSIZE(const void *PTR)
Definition varatt.h:298

References Assert, DatumGetPointer(), detoast_external_attr(), ereport, errcode(), errmsg, ERROR, fb(), heap_compute_data_size(), heap_fill_tuple(), HEAP_HASEXTERNAL, HEAP_HASVARWIDTH, i, INDEX_MAX_KEYS, INDEX_NULL_MASK, INDEX_SIZE_MASK, INDEX_VAR_MASK, IndexInfoFindDataOffset(), MAXALIGN, MemoryContextAllocZero(), pfree(), PointerGetDatum(), IndexTupleData::t_info, toast_compress_datum(), TOAST_INDEX_HACK, TOAST_INDEX_TARGET, TupleDescAttr(), values, VARATT_IS_EXTENDED(), VARATT_IS_EXTERNAL(), and VARSIZE().

Referenced by index_form_tuple(), and tuplesort_putindextuplevalues().

◆ index_getattr()

static Datum index_getattr ( IndexTuple  tup,
int  attnum,
TupleDesc  tupleDesc,
bool isnull 
)
inlinestatic

◆ index_truncate_tuple()

IndexTuple index_truncate_tuple ( TupleDesc  sourceDescriptor,
IndexTuple  source,
int  leavenatts 
)
extern

Definition at line 508 of file indextuple.c.

510{
513 bool isnull[INDEX_MAX_KEYS];
514 IndexTuple truncated;
515
517
518 /* Easy case: no truncation actually required */
519 if (leavenatts == sourceDescriptor->natts)
520 return CopyIndexTuple(source);
521
522 /* Create temporary truncated tuple descriptor */
524
525 /* Deform, form copy of tuple with fewer attributes */
527 truncated = index_form_tuple(truncdesc, values, isnull);
528 truncated->t_tid = source->t_tid;
530
531 /*
532 * Cannot leak memory here, TupleDescCopy() doesn't allocate any inner
533 * structure, so, plain pfree() should clean all allocated memory
534 */
536
537 return truncated;
538}
void index_deform_tuple(IndexTuple tup, TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition indextuple.c:364
IndexTuple CopyIndexTuple(IndexTuple source)
Definition indextuple.c:479
IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition indextuple.c:44
ItemPointerData t_tid
Definition itup.h:37
TupleDesc CreateTupleDescTruncatedCopy(TupleDesc tupdesc, int natts)
Definition tupdesc.c:289

References Assert, CopyIndexTuple(), CreateTupleDescTruncatedCopy(), fb(), index_deform_tuple(), index_form_tuple(), INDEX_MAX_KEYS, IndexTupleSize(), pfree(), source, IndexTupleData::t_tid, and values.

Referenced by _bt_truncate().

◆ IndexInfoFindDataOffset()

static Size IndexInfoFindDataOffset ( unsigned short  t_info)
inlinestatic

Definition at line 112 of file itup.h.

114{
115 if (!(t_info & INDEX_NULL_MASK))
116 return MAXALIGN(sizeof(IndexTupleData));
117 else
118 return MAXALIGN(sizeof(IndexTupleData) + sizeof(IndexAttributeBitMapData));

References INDEX_NULL_MASK, and MAXALIGN.

Referenced by _hash_get_indextuple_hashkey(), bt_page_print_tuples(), index_deform_tuple(), index_form_tuple_context(), index_getattr(), and nocache_index_getattr().

◆ IndexTupleHasNulls()

static bool IndexTupleHasNulls ( const IndexTupleData itup)
inlinestatic

◆ IndexTupleHasVarwidths()

static bool IndexTupleHasVarwidths ( const IndexTupleData itup)
inlinestatic

Definition at line 83 of file itup.h.

85{
86 return itup->t_info & INDEX_VAR_MASK;

References INDEX_VAR_MASK, and IndexTupleData::t_info.

Referenced by bt_normalize_tuple(), bt_page_print_tuples(), and nocache_index_getattr().

◆ IndexTupleSize()

static Size IndexTupleSize ( const IndexTupleData itup)
inlinestatic

Definition at line 71 of file itup.h.

73{
74 return (itup->t_info & INDEX_SIZE_MASK);

References INDEX_SIZE_MASK, and IndexTupleData::t_info.

Referenced by _bt_buildadd(), _bt_check_third_page(), _bt_dedup_finish_pending(), _bt_dedup_save_htid(), _bt_dedup_start_pending(), _bt_delitems_delete(), _bt_delitems_vacuum(), _bt_doinsert(), _bt_form_posting(), _bt_insert_parent(), _bt_insertonpg(), _bt_mark_page_halfdead(), _bt_recsplitloc(), _bt_restore_page(), _bt_saveitem(), _bt_sort_dedup_finish_pending(), _bt_split(), _bt_truncate(), _hash_doinsert(), _hash_pgaddmultitup(), _hash_splitbucket(), _hash_squeezebucket(), bt_check_level_from_leftmost(), bt_page_print_tuples(), bt_pivot_tuple_identical(), bt_rootdescend(), bt_target_page_check(), bt_tuple_present_callback(), btree_xlog_insert(), btree_xlog_split(), btree_xlog_updates(), BTreeTupleGetHeapTID(), CopyIndexTuple(), decodePageSplitRecord(), entryExecPlaceToPage(), entryIsEnoughSpace(), entrySplitPage(), GetBTPageStatistics(), gin_check_parent_keys_consistency(), ginEntryFillRoot(), GinFormInteriorTuple(), GinFormTuple(), ginHeapTupleFastCollect(), ginHeapTupleFastInsert(), ginRedoInsertEntry(), ginRedoInsertListPage(), ginRedoUpdateMetapage(), ginVacuumEntryPage(), gist_indexsortbuild_levelstate_add(), gist_indexsortbuild_levelstate_flush(), gist_page_items(), gist_page_items_bytea(), gistBuildCallback(), gistfillbuffer(), gistfillitupvec(), gistfitpage(), gistGetItupFromPage(), gistnospace(), gistPlaceItupToPage(), gistplacetopage(), gistRedoPageUpdateRecord(), gistSplit(), gistXLogUpdate(), hash_xlog_move_page_contents(), hash_xlog_squeeze_page(), index_truncate_tuple(), makeSublist(), spgFormInnerTuple(), writeListPage(), and writetup_index().

◆ nocache_index_getattr()

Datum nocache_index_getattr ( IndexTuple  tup,
int  attnum,
TupleDesc  tupleDesc 
)
extern

Definition at line 229 of file indextuple.c.

232{
234 char *tp; /* ptr to data part of tuple */
235 bits8 *bp = NULL; /* ptr to null bitmap in tuple */
236 int data_off; /* tuple data offset */
237 int off; /* current offset within data */
238 int startAttr;
239 int firstNullAttr;
241 int i;
242
243 /* Did someone forget to call TupleDescFinalize()? */
244 Assert(tupleDesc->firstNonCachedOffsetAttr >= 0);
245
246 attnum--;
247
249 tp = (char *) tup + data_off;
250
251 /*
252 * To minimize the number of attributes we need to look at, start walking
253 * the tuple at the attribute with the highest attcacheoff prior to attnum
254 * or the first NULL attribute prior to attnum, whichever comes first.
255 */
256 if (hasnulls)
257 {
258 bp = (bits8 *) ((char *) tup + sizeof(IndexTupleData));
260 }
261 else
263
264 if (tupleDesc->firstNonCachedOffsetAttr > 0 && firstNullAttr > 0)
265 {
266 /*
267 * Try to start with the highest attribute with an attcacheoff that's
268 * prior to the one we're looking for, or with the attribute prior to
269 * the first NULL attribute, if there is one.
270 */
271 startAttr = Min(tupleDesc->firstNonCachedOffsetAttr - 1, firstNullAttr - 1);
273 }
274 else
275 {
276 /* Otherwise, start at the beginning... */
277 startAttr = 0;
278 off = 0;
279 }
280
281 /*
282 * Calculate 'off' up to the first NULL attr. We use two cheaper loops
283 * when the tuple has no variable-width columns. When variable-width
284 * columns exists, we use att_addlength_pointer() to move the offset
285 * beyond the current attribute.
286 */
288 {
289 /* Calculate the offset up until the first NULL */
290 for (i = startAttr; i < firstNullAttr; i++)
291 {
293
294 off = att_pointer_alignby(off,
295 cattr->attalignby,
296 cattr->attlen,
297 tp + off);
298 off = att_addlength_pointer(off, cattr->attlen, tp + off);
299 }
300
301 /* Calculate the offset for any remaining columns. */
302 for (; i < attnum; i++)
303 {
305
306 if (att_isnull(i, bp))
307 continue;
308
310
311 off = att_pointer_alignby(off,
312 cattr->attalignby,
313 cattr->attlen,
314 tp + off);
315 off = att_addlength_pointer(off, cattr->attlen, tp + off);
316 }
317 }
318 else
319 {
320 /* Handle tuples with only fixed-width attributes */
321
322 /* Calculate the offset up until the first NULL */
323 for (i = startAttr; i < firstNullAttr; i++)
324 {
326
327 Assert(cattr->attlen > 0);
328 off = att_nominal_alignby(off, cattr->attalignby);
329 off += cattr->attlen;
330 }
331
332 /* Calculate the offset for any remaining columns. */
333 for (; i < attnum; i++)
334 {
336
337 if (att_isnull(i, bp))
338 continue;
339
341
342 Assert(cattr->attlen > 0);
343 off = att_nominal_alignby(off, cattr->attalignby);
344 off += cattr->attlen;
345 }
346 }
347
349 off = att_pointer_alignby(off, cattr->attalignby,
350 cattr->attlen, tp + off);
351 return fetchatt(cattr, tp + off);
352}
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition tupmacs.h:431
#define att_pointer_alignby(cur_offset, attalignby, attlen, attptr)
Definition tupmacs.h:383

References Assert, att_addlength_pointer, att_isnull(), att_nominal_alignby, att_pointer_alignby, CompactAttribute::attcacheoff, attnum, fb(), fetchatt, first_null_attr(), i, IndexInfoFindDataOffset(), IndexTupleHasNulls(), IndexTupleHasVarwidths(), Min, and TupleDescCompactAttr().

Referenced by index_getattr().