14 #ifndef HTUP_DETAILS_H 15 #define HTUP_DETAILS_H 33 #define MaxTupleAttributeNumber 1664 47 #define MaxHeapAttributeNumber 1600 165 #define FIELDNO_HEAPTUPLEHEADERDATA_INFOMASK2 2 168 #define FIELDNO_HEAPTUPLEHEADERDATA_INFOMASK 3 171 #define FIELDNO_HEAPTUPLEHEADERDATA_HOFF 4 176 #define FIELDNO_HEAPTUPLEHEADERDATA_BITS 5 184 #define SizeofHeapTupleHeader offsetof(HeapTupleHeaderData, t_bits) 189 #define HEAP_HASNULL 0x0001 190 #define HEAP_HASVARWIDTH 0x0002 191 #define HEAP_HASEXTERNAL 0x0004 192 #define HEAP_HASOID_OLD 0x0008 193 #define HEAP_XMAX_KEYSHR_LOCK 0x0010 194 #define HEAP_COMBOCID 0x0020 195 #define HEAP_XMAX_EXCL_LOCK 0x0040 196 #define HEAP_XMAX_LOCK_ONLY 0x0080 199 #define HEAP_XMAX_SHR_LOCK (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK) 201 #define HEAP_LOCK_MASK (HEAP_XMAX_SHR_LOCK | HEAP_XMAX_EXCL_LOCK | \ 202 HEAP_XMAX_KEYSHR_LOCK) 203 #define HEAP_XMIN_COMMITTED 0x0100 204 #define HEAP_XMIN_INVALID 0x0200 205 #define HEAP_XMIN_FROZEN (HEAP_XMIN_COMMITTED|HEAP_XMIN_INVALID) 206 #define HEAP_XMAX_COMMITTED 0x0400 207 #define HEAP_XMAX_INVALID 0x0800 208 #define HEAP_XMAX_IS_MULTI 0x1000 209 #define HEAP_UPDATED 0x2000 210 #define HEAP_MOVED_OFF 0x4000 213 #define HEAP_MOVED_IN 0x8000 216 #define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN) 218 #define HEAP_XACT_MASK 0xFFF0 230 #define HEAP_XMAX_IS_LOCKED_ONLY(infomask) \ 231 (((infomask) & HEAP_XMAX_LOCK_ONLY) || \ 232 (((infomask) & (HEAP_XMAX_IS_MULTI | HEAP_LOCK_MASK)) == HEAP_XMAX_EXCL_LOCK)) 252 #define HEAP_LOCKED_UPGRADED(infomask) \ 254 ((infomask) & HEAP_XMAX_IS_MULTI) != 0 && \ 255 ((infomask) & HEAP_XMAX_LOCK_ONLY) != 0 && \ 256 (((infomask) & (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)) == 0) \ 262 #define HEAP_XMAX_IS_SHR_LOCKED(infomask) \ 263 (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_SHR_LOCK) 264 #define HEAP_XMAX_IS_EXCL_LOCKED(infomask) \ 265 (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_EXCL_LOCK) 266 #define HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) \ 267 (((infomask) & HEAP_LOCK_MASK) == HEAP_XMAX_KEYSHR_LOCK) 270 #define HEAP_XMAX_BITS (HEAP_XMAX_COMMITTED | HEAP_XMAX_INVALID | \ 271 HEAP_XMAX_IS_MULTI | HEAP_LOCK_MASK | HEAP_XMAX_LOCK_ONLY) 276 #define HEAP_NATTS_MASK 0x07FF 278 #define HEAP_KEYS_UPDATED 0x2000 280 #define HEAP_HOT_UPDATED 0x4000 281 #define HEAP_ONLY_TUPLE 0x8000 283 #define HEAP2_XACT_MASK 0xE000 291 #define HEAP_TUPLE_HAS_MATCH HEAP_ONLY_TUPLE 308 #define HeapTupleHeaderGetRawXmin(tup) \ 310 (tup)->t_choice.t_heap.t_xmin \ 313 #define HeapTupleHeaderGetXmin(tup) \ 315 HeapTupleHeaderXminFrozen(tup) ? \ 316 FrozenTransactionId : HeapTupleHeaderGetRawXmin(tup) \ 319 #define HeapTupleHeaderSetXmin(tup, xid) \ 321 (tup)->t_choice.t_heap.t_xmin = (xid) \ 324 #define HeapTupleHeaderXminCommitted(tup) \ 326 ((tup)->t_infomask & HEAP_XMIN_COMMITTED) != 0 \ 329 #define HeapTupleHeaderXminInvalid(tup) \ 331 ((tup)->t_infomask & (HEAP_XMIN_COMMITTED|HEAP_XMIN_INVALID)) == \ 335 #define HeapTupleHeaderXminFrozen(tup) \ 337 ((tup)->t_infomask & (HEAP_XMIN_FROZEN)) == HEAP_XMIN_FROZEN \ 340 #define HeapTupleHeaderSetXminCommitted(tup) \ 342 AssertMacro(!HeapTupleHeaderXminInvalid(tup)), \ 343 ((tup)->t_infomask |= HEAP_XMIN_COMMITTED) \ 346 #define HeapTupleHeaderSetXminInvalid(tup) \ 348 AssertMacro(!HeapTupleHeaderXminCommitted(tup)), \ 349 ((tup)->t_infomask |= HEAP_XMIN_INVALID) \ 352 #define HeapTupleHeaderSetXminFrozen(tup) \ 354 AssertMacro(!HeapTupleHeaderXminInvalid(tup)), \ 355 ((tup)->t_infomask |= HEAP_XMIN_FROZEN) \ 365 #define HeapTupleHeaderGetUpdateXid(tup) \ 367 (!((tup)->t_infomask & HEAP_XMAX_INVALID) && \ 368 ((tup)->t_infomask & HEAP_XMAX_IS_MULTI) && \ 369 !((tup)->t_infomask & HEAP_XMAX_LOCK_ONLY)) ? \ 370 HeapTupleGetUpdateXid(tup) \ 372 HeapTupleHeaderGetRawXmax(tup) \ 375 #define HeapTupleHeaderGetRawXmax(tup) \ 377 (tup)->t_choice.t_heap.t_xmax \ 380 #define HeapTupleHeaderSetXmax(tup, xid) \ 382 (tup)->t_choice.t_heap.t_xmax = (xid) \ 391 #define HeapTupleHeaderGetRawCommandId(tup) \ 393 (tup)->t_choice.t_heap.t_field3.t_cid \ 397 #define HeapTupleHeaderSetCmin(tup, cid) \ 399 Assert(!((tup)->t_infomask & HEAP_MOVED)); \ 400 (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \ 401 (tup)->t_infomask &= ~HEAP_COMBOCID; \ 405 #define HeapTupleHeaderSetCmax(tup, cid, iscombo) \ 407 Assert(!((tup)->t_infomask & HEAP_MOVED)); \ 408 (tup)->t_choice.t_heap.t_field3.t_cid = (cid); \ 410 (tup)->t_infomask |= HEAP_COMBOCID; \ 412 (tup)->t_infomask &= ~HEAP_COMBOCID; \ 415 #define HeapTupleHeaderGetXvac(tup) \ 417 ((tup)->t_infomask & HEAP_MOVED) ? \ 418 (tup)->t_choice.t_heap.t_field3.t_xvac \ 420 InvalidTransactionId \ 423 #define HeapTupleHeaderSetXvac(tup, xid) \ 425 Assert((tup)->t_infomask & HEAP_MOVED); \ 426 (tup)->t_choice.t_heap.t_field3.t_xvac = (xid); \ 429 #define HeapTupleHeaderIsSpeculative(tup) \ 431 (ItemPointerGetOffsetNumberNoCheck(&(tup)->t_ctid) == SpecTokenOffsetNumber) \ 434 #define HeapTupleHeaderGetSpeculativeToken(tup) \ 436 AssertMacro(HeapTupleHeaderIsSpeculative(tup)), \ 437 ItemPointerGetBlockNumber(&(tup)->t_ctid) \ 440 #define HeapTupleHeaderSetSpeculativeToken(tup, token) \ 442 ItemPointerSet(&(tup)->t_ctid, token, SpecTokenOffsetNumber) \ 445 #define HeapTupleHeaderIndicatesMovedPartitions(tup) \ 446 (ItemPointerGetOffsetNumber(&(tup)->t_ctid) == MovedPartitionsOffsetNumber && \ 447 ItemPointerGetBlockNumberNoCheck(&(tup)->t_ctid) == MovedPartitionsBlockNumber) 449 #define HeapTupleHeaderSetMovedPartitions(tup) \ 450 ItemPointerSet(&(tup)->t_ctid, MovedPartitionsBlockNumber, MovedPartitionsOffsetNumber) 452 #define HeapTupleHeaderGetDatumLength(tup) \ 455 #define HeapTupleHeaderSetDatumLength(tup, len) \ 456 SET_VARSIZE(tup, len) 458 #define HeapTupleHeaderGetTypeId(tup) \ 460 (tup)->t_choice.t_datum.datum_typeid \ 463 #define HeapTupleHeaderSetTypeId(tup, typeid) \ 465 (tup)->t_choice.t_datum.datum_typeid = (typeid) \ 468 #define HeapTupleHeaderGetTypMod(tup) \ 470 (tup)->t_choice.t_datum.datum_typmod \ 473 #define HeapTupleHeaderSetTypMod(tup, typmod) \ 475 (tup)->t_choice.t_datum.datum_typmod = (typmod) \ 484 #define HeapTupleHeaderIsHotUpdated(tup) \ 486 ((tup)->t_infomask2 & HEAP_HOT_UPDATED) != 0 && \ 487 ((tup)->t_infomask & HEAP_XMAX_INVALID) == 0 && \ 488 !HeapTupleHeaderXminInvalid(tup) \ 491 #define HeapTupleHeaderSetHotUpdated(tup) \ 493 (tup)->t_infomask2 |= HEAP_HOT_UPDATED \ 496 #define HeapTupleHeaderClearHotUpdated(tup) \ 498 (tup)->t_infomask2 &= ~HEAP_HOT_UPDATED \ 501 #define HeapTupleHeaderIsHeapOnly(tup) \ 503 ((tup)->t_infomask2 & HEAP_ONLY_TUPLE) != 0 \ 506 #define HeapTupleHeaderSetHeapOnly(tup) \ 508 (tup)->t_infomask2 |= HEAP_ONLY_TUPLE \ 511 #define HeapTupleHeaderClearHeapOnly(tup) \ 513 (tup)->t_infomask2 &= ~HEAP_ONLY_TUPLE \ 516 #define HeapTupleHeaderHasMatch(tup) \ 518 ((tup)->t_infomask2 & HEAP_TUPLE_HAS_MATCH) != 0 \ 521 #define HeapTupleHeaderSetMatch(tup) \ 523 (tup)->t_infomask2 |= HEAP_TUPLE_HAS_MATCH \ 526 #define HeapTupleHeaderClearMatch(tup) \ 528 (tup)->t_infomask2 &= ~HEAP_TUPLE_HAS_MATCH \ 531 #define HeapTupleHeaderGetNatts(tup) \ 532 ((tup)->t_infomask2 & HEAP_NATTS_MASK) 534 #define HeapTupleHeaderSetNatts(tup, natts) \ 536 (tup)->t_infomask2 = ((tup)->t_infomask2 & ~HEAP_NATTS_MASK) | (natts) \ 539 #define HeapTupleHeaderHasExternal(tup) \ 540 (((tup)->t_infomask & HEAP_HASEXTERNAL) != 0) 547 #define BITMAPLEN(NATTS) (((int)(NATTS) + 7) / 8) 560 #define MaxHeapTupleSize (BLCKSZ - MAXALIGN(SizeOfPageHeaderData + sizeof(ItemIdData))) 561 #define MinHeapTupleSize MAXALIGN(SizeofHeapTupleHeader) 574 #define MaxHeapTuplesPerPage \ 575 ((int) ((BLCKSZ - SizeOfPageHeaderData) / \ 576 (MAXALIGN(SizeofHeapTupleHeader) + sizeof(ItemIdData)))) 585 #define MaxAttrSize (10 * 1024 * 1024) 619 #define MINIMAL_TUPLE_OFFSET \ 620 ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF) 621 #define MINIMAL_TUPLE_PADDING \ 622 ((offsetof(HeapTupleHeaderData, t_infomask2) - sizeof(uint32)) % MAXIMUM_ALIGNOF) 623 #define MINIMAL_TUPLE_DATA_OFFSET \ 624 offsetof(MinimalTupleData, t_infomask2) 649 #define SizeofMinimalTupleHeader offsetof(MinimalTupleData, t_bits) 655 #define GETSTRUCT(TUP) ((char *) ((TUP)->t_data) + (TUP)->t_data->t_hoff) 661 #define HeapTupleHasNulls(tuple) \ 662 (((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0) 664 #define HeapTupleNoNulls(tuple) \ 665 (!((tuple)->t_data->t_infomask & HEAP_HASNULL)) 667 #define HeapTupleHasVarWidth(tuple) \ 668 (((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0) 670 #define HeapTupleAllFixed(tuple) \ 671 (!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH)) 673 #define HeapTupleHasExternal(tuple) \ 674 (((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0) 676 #define HeapTupleIsHotUpdated(tuple) \ 677 HeapTupleHeaderIsHotUpdated((tuple)->t_data) 679 #define HeapTupleSetHotUpdated(tuple) \ 680 HeapTupleHeaderSetHotUpdated((tuple)->t_data) 682 #define HeapTupleClearHotUpdated(tuple) \ 683 HeapTupleHeaderClearHotUpdated((tuple)->t_data) 685 #define HeapTupleIsHeapOnly(tuple) \ 686 HeapTupleHeaderIsHeapOnly((tuple)->t_data) 688 #define HeapTupleSetHeapOnly(tuple) \ 689 HeapTupleHeaderSetHeapOnly((tuple)->t_data) 691 #define HeapTupleClearHeapOnly(tuple) \ 692 HeapTupleHeaderClearHeapOnly((tuple)->t_data) 710 #if !defined(DISABLE_COMPLEX_MACRO) 712 #define fastgetattr(tup, attnum, tupleDesc, isnull) \ 714 AssertMacro((attnum) > 0), \ 715 (*(isnull) = false), \ 716 HeapTupleNoNulls(tup) ? \ 718 TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff >= 0 ? \ 720 fetchatt(TupleDescAttr((tupleDesc), (attnum)-1), \ 721 (char *) (tup)->t_data + (tup)->t_data->t_hoff + \ 722 TupleDescAttr((tupleDesc), (attnum)-1)->attcacheoff)\ 725 nocachegetattr((tup), (attnum), (tupleDesc)) \ 729 att_isnull((attnum)-1, (tup)->t_data->t_bits) ? \ 731 (*(isnull) = true), \ 736 nocachegetattr((tup), (attnum), (tupleDesc)) \ 762 #define heap_getattr(tup, attnum, tupleDesc, isnull) \ 766 ((attnum) > (int) HeapTupleHeaderGetNatts((tup)->t_data)) ? \ 767 getmissingattr((tupleDesc), (attnum), (isnull)) \ 769 fastgetattr((tup), (attnum), (tupleDesc), (isnull)) \ 772 heap_getsysattr((tup), (attnum), (tupleDesc), (isnull)) \ 781 char *data,
Size data_size,
789 int attnum,
bool *isnull);
#define fastgetattr(tup, attnum, tupleDesc, isnull)
union HeapTupleFields::@42 t_field3
Size heap_compute_data_size(TupleDesc tupleDesc, Datum *values, bool *isnull)
void heap_freetuple(HeapTuple htup)
HeapTuple heap_tuple_from_minimal_tuple(MinimalTuple mtup)
void heap_copytuple_with_tuple(HeapTuple src, HeapTuple dest)
#define FLEXIBLE_ARRAY_MEMBER
struct DatumTupleFields DatumTupleFields
Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
size_t varsize_any(void *p)
void heap_free_minimal_tuple(MinimalTuple mtup)
Datum getmissingattr(TupleDesc tupleDesc, int attnum, bool *isnull)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup)
#define MINIMAL_TUPLE_PADDING
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
struct HeapTupleFields HeapTupleFields
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup)
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_modify_tuple_by_cols(HeapTuple tuple, TupleDesc tupleDesc, int nCols, int *replCols, Datum *replValues, bool *replIsnull)
MinimalTuple minimal_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc)
Datum bit(PG_FUNCTION_ARGS)
HeapTuple heap_expand_tuple(HeapTuple sourceTuple, TupleDesc tupleDesc)
Datum nocachegetattr(HeapTuple tup, int attnum, TupleDesc att)
static Datum values[MAXATTR]
void heap_fill_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull, char *data, Size data_size, uint16 *infomask, bits8 *bit)
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)