1/*-------------------------------------------------------------------------
4 * POSTGRES tuple descriptor definitions.
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/tupdesc.h
12 *-------------------------------------------------------------------------
25 char *
adbin;
/* nodeToString representation of expr */
31 char *
ccbin;
/* nodeToString representation of expr */
37/* This structure contains constraints of a tuple */
52 * Cut-down version of FormData_pg_attribute for faster access for tasks
53 * such as tuple deformation. The fields of this struct are populated
54 * using the populate_compact_attribute() function, which must be called
55 * directly after the FormData_pg_attribute struct is populated or
58 * Currently, this struct is 16 bytes. Any code changes which enlarge this
59 * struct should be considered very carefully.
61 * Code which must access a TupleDesc's attribute data should always make use
62 * the fields of this struct when required fields are available here. It's
63 * more efficient to access the memory in CompactAttribute due to it being a
64 * more compact representation of FormData_pg_attribute and also because
65 * accessing the FormData_pg_attribute requires an additional calculations to
66 * obtain the base address of the array within the TupleDesc.
73 bool attbyval;
/* as FormData_pg_attribute.attbyval */
78 bool attgenerated;
/* FormData_pg_attribute.attgenerated != '0円' */
83/* Valid values for CompactAttribute->attnullability */
84 #define ATTNULLABLE_UNRESTRICTED 'f' /* No constraint exists */
85 #define ATTNULLABLE_UNKNOWN 'u' /* constraint exists, validity unknown */
86 #define ATTNULLABLE_VALID 'v' /* valid constraint exists */
87 #define ATTNULLABLE_INVALID 'i' /* constraint exists, marked invalid */
90 * This struct is passed around within the backend to describe the structure
91 * of tuples. For tuples coming from on-disk relations, the information is
92 * collected from the pg_attribute, pg_attrdef, and pg_constraint catalogs.
93 * Transient row types (such as the result of a join query) have anonymous
94 * TupleDesc structs that generally omit any constraint info; therefore the
95 * structure is designed to let the constraints be omitted efficiently.
97 * Note that only user attributes, not system attributes, are mentioned in
100 * If the tupdesc is known to correspond to a named rowtype (such as a table's
101 * rowtype) then tdtypeid identifies that type and tdtypmod is -1. Otherwise
102 * tdtypeid is RECORDOID, and tdtypmod can be either -1 for a fully anonymous
103 * row type, or a value >= 0 to allow the rowtype to be looked up in the
104 * typcache.c type cache.
106 * Note that tdtypeid is never the OID of a domain over composite, even if
107 * we are dealing with values that are known (at some higher level) to be of
108 * a domain-over-composite type. This is because tdtypeid/tdtypmod need to
109 * match up with the type labeling of composite Datums, and those are never
110 * explicitly marked as being of a domain type, either.
112 * Tuple descriptors that live in caches (relcache or typcache, at present)
113 * are reference-counted: they can be deleted when their reference count goes
114 * to zero. Tuple descriptors created by the executor need no reference
115 * counting, however: they are simply created in the appropriate memory
116 * context and go away when the context is freed. We set the tdrefcount
117 * field of such a descriptor to -1, while reference-counted descriptors
118 * always have tdrefcount >= 0.
120 * Beyond the compact_attrs variable length array, the TupleDesc stores an
121 * array of FormData_pg_attribute. The TupleDescAttr() function, as defined
122 * below, takes care of calculating the address of the elements of the
123 * FormData_pg_attribute array.
125 * The array of CompactAttribute is effectively an abbreviated version of the
126 * array of FormData_pg_attribute. Because CompactAttribute is significantly
127 * smaller than FormData_pg_attribute, code, especially performance-critical
128 * code, should prioritize using the fields from the CompactAttribute over the
129 * equivalent fields in FormData_pg_attribute.
131 * Any code making changes manually to and fields in the FormData_pg_attribute
132 * array must subsequently call populate_compact_attribute() to flush the
133 * changes out to the corresponding 'compact_attrs' element.
137 int natts;
/* number of attributes in the tuple */
142 /* compact_attrs[N] is the compact metadata of Attribute Number N+1 */
150 * Calculates the base address of the Form_pg_attribute at the end of the
151 * TupleDescData struct.
153 #define TupleDescAttrAddress(desc) \
154 (Form_pg_attribute) ((char *) (desc) + \
155 (offsetof(struct TupleDescData, compact_attrs) + \
156 (desc)->natts * sizeof(CompactAttribute)))
158/* Accessor for the i'th FormData_pg_attribute element of tupdesc. */
167#undef TupleDescAttrAddress
172 * Accessor for the i'th CompactAttribute element of tupdesc.
179#ifdef USE_ASSERT_CHECKING
181 /* Check that the CompactAttribute is correctly populated */
198 #define TupleDescSize(src) \
199 (offsetof(struct TupleDescData, compact_attrs) + \
200 (src)->natts * sizeof(CompactAttribute) + \
201 (src)->natts * sizeof(FormData_pg_attribute))
213 #define PinTupleDesc(tupdesc) \
215 if ((tupdesc)->tdrefcount >= 0) \
216 IncrTupleDescRefCount(tupdesc); \
219 #define ReleaseTupleDesc(tupdesc) \
221 if ((tupdesc)->tdrefcount >= 0) \
222 DecrTupleDescRefCount(tupdesc); \
231 const char *attributeName,
238 const char *attributeName,
251#endif /* TUPDESC_H */
#define FLEXIBLE_ARRAY_MEMBER
FormData_pg_attribute * Form_pg_attribute
bool has_generated_virtual
bool has_generated_stored
struct AttrMissing * missing
CompactAttribute compact_attrs[FLEXIBLE_ARRAY_MEMBER]
#define TupleDescAttrAddress(desc)
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
void TupleDescCopy(TupleDesc dst, TupleDesc src)
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
void DecrTupleDescRefCount(TupleDesc tupdesc)
struct TupleConstr TupleConstr
void FreeTupleDesc(TupleDesc tupdesc)
void IncrTupleDescRefCount(TupleDesc tupdesc)
TupleDesc CreateTemplateTupleDesc(int natts)
struct AttrDefault AttrDefault
void verify_compact_attribute(TupleDesc, int attnum)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
uint32 hashRowType(TupleDesc desc)
TupleDesc CreateTupleDescTruncatedCopy(TupleDesc tupdesc, int natts)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
void TupleDescInitBuiltinEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
TupleDesc BuildDescFromLists(const List *names, const List *types, const List *typmods, const List *collations)
struct TupleDescData TupleDescData
struct CompactAttribute CompactAttribute
void populate_compact_attribute(TupleDesc tupdesc, int attnum)
bool equalRowTypes(TupleDesc tupdesc1, TupleDesc tupdesc2)
struct TupleDescData * TupleDesc
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
TupleDesc CreateTupleDesc(int natts, Form_pg_attribute *attrs)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
bool equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
void TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno, TupleDesc src, AttrNumber srcAttno)
struct ConstrCheck ConstrCheck