htup.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*-------------------------------------------------------------------------
  2. *
  3. * htup.h
  4. * POSTGRES heap tuple definitions.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/access/htup.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef HTUP_H
  15. #define HTUP_H
  16. #include "storage/itemptr.h"
  17. /* typedefs and forward declarations for structs defined in htup_details.h */
  18. typedef struct HeapTupleHeaderData HeapTupleHeaderData;
  19. typedef HeapTupleHeaderData *HeapTupleHeader;
  20. typedef struct MinimalTupleData MinimalTupleData;
  21. typedef MinimalTupleData *MinimalTuple;
  22. /*
  23. * HeapTupleData is an in-memory data structure that points to a tuple.
  24. *
  25. * There are several ways in which this data structure is used:
  26. *
  27. * * Pointer to a tuple in a disk buffer: t_data points directly into the
  28. * buffer (which the code had better be holding a pin on, but this is not
  29. * reflected in HeapTupleData itself).
  30. *
  31. * * Pointer to nothing: t_data is NULL. This is used as a failure indication
  32. * in some functions.
  33. *
  34. * * Part of a palloc'd tuple: the HeapTupleData itself and the tuple
  35. * form a single palloc'd chunk. t_data points to the memory location
  36. * immediately following the HeapTupleData struct (at offset HEAPTUPLESIZE).
  37. * This is the output format of heap_form_tuple and related routines.
  38. *
  39. * * Separately allocated tuple: t_data points to a palloc'd chunk that
  40. * is not adjacent to the HeapTupleData. (This case is deprecated since
  41. * it's difficult to tell apart from case #1. It should be used only in
  42. * limited contexts where the code knows that case #1 will never apply.)
  43. *
  44. * * Separately allocated minimal tuple: t_data points MINIMAL_TUPLE_OFFSET
  45. * bytes before the start of a MinimalTuple. As with the previous case,
  46. * this can't be told apart from case #1 by inspection; code setting up
  47. * or destroying this representation has to know what it's doing.
  48. *
  49. * t_len should always be valid, except in the pointer-to-nothing case.
  50. * t_self and t_tableOid should be valid if the HeapTupleData points to
  51. * a disk buffer, or if it represents a copy of a tuple on disk. They
  52. * should be explicitly set invalid in manufactured tuples.
  53. */
  54. typedef struct HeapTupleData
  55. {
  56. uint32 t_len; /* length of *t_data */
  57. ItemPointerData t_self; /* SelfItemPointer */
  58. Oid t_tableOid; /* table the tuple came from */
  59. #define FIELDNO_HEAPTUPLEDATA_DATA 3
  60. HeapTupleHeader t_data; /* -> tuple header and data */
  61. } HeapTupleData;
  62. typedef HeapTupleData *HeapTuple;
  63. #define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData))
  64. /*
  65. * Accessor macros to be used with HeapTuple pointers.
  66. */
  67. #define HeapTupleIsValid(tuple) PointerIsValid(tuple)
  68. /* HeapTupleHeader functions implemented in utils/time/combocid.c */
  69. extern CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup);
  70. extern CommandId HeapTupleHeaderGetCmax(HeapTupleHeader tup);
  71. extern void HeapTupleHeaderAdjustCmax(HeapTupleHeader tup,
  72. CommandId *cmax, bool *iscombo);
  73. /* Prototype for HeapTupleHeader accessors in heapam.c */
  74. extern TransactionId HeapTupleGetUpdateXid(HeapTupleHeader tuple);
  75. #endif /* HTUP_H */