PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tupdesc.h File Reference
#include "access/attnum.h"
#include "catalog/pg_attribute.h"
#include "nodes/pg_list.h"
Include dependency graph for tupdesc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AttrDefault
 
struct  ConstrCheck
 
struct  TupleConstr
 
struct  CompactAttribute
 
struct  TupleDescData
 

Macros

#define ATTNULLABLE_UNRESTRICTED   'f' /* No constraint exists */
 
#define ATTNULLABLE_UNKNOWN   'u' /* constraint exists, validity unknown */
 
#define ATTNULLABLE_VALID   'v' /* valid constraint exists */
 
#define ATTNULLABLE_INVALID   'i' /* constraint exists, marked invalid */
 
#define TupleDescAttrAddress(desc)
 
#define TupleDescSize(src)
 
#define PinTupleDesc(tupdesc)
 
#define ReleaseTupleDesc(tupdesc)
 

Typedefs

typedef struct AttrDefault AttrDefault
 
typedef struct ConstrCheck ConstrCheck
 
typedef struct TupleConstr TupleConstr
 
typedef struct CompactAttribute CompactAttribute
 
typedef struct TupleDescData TupleDescData
 
typedef struct TupleDescDataTupleDesc
 

Functions

void populate_compact_attribute (TupleDesc tupdesc, int attnum)
 
static FormData_pg_attributeTupleDescAttr (TupleDesc tupdesc, int i)
 
void verify_compact_attribute (TupleDesc, int attnum)
 
static CompactAttributeTupleDescCompactAttr (TupleDesc tupdesc, int i)
 
TupleDesc CreateTemplateTupleDesc (int natts)
 
TupleDesc CreateTupleDesc (int natts, Form_pg_attribute *attrs)
 
TupleDesc CreateTupleDescCopy (TupleDesc tupdesc)
 
TupleDesc CreateTupleDescTruncatedCopy (TupleDesc tupdesc, int natts)
 
TupleDesc CreateTupleDescCopyConstr (TupleDesc tupdesc)
 
void TupleDescCopy (TupleDesc dst, TupleDesc src)
 
void TupleDescCopyEntry (TupleDesc dst, AttrNumber dstAttno, TupleDesc src, AttrNumber srcAttno)
 
void FreeTupleDesc (TupleDesc tupdesc)
 
void IncrTupleDescRefCount (TupleDesc tupdesc)
 
void DecrTupleDescRefCount (TupleDesc tupdesc)
 
bool equalTupleDescs (TupleDesc tupdesc1, TupleDesc tupdesc2)
 
bool equalRowTypes (TupleDesc tupdesc1, TupleDesc tupdesc2)
 
uint32 hashRowType (TupleDesc desc)
 
void TupleDescInitEntry (TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
 
void TupleDescInitBuiltinEntry (TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
 
void TupleDescInitEntryCollation (TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
 
TupleDesc BuildDescFromLists (const List *names, const List *types, const List *typmods, const List *collations)
 
NodeTupleDescGetDefault (TupleDesc tupdesc, AttrNumber attnum)
 

Macro Definition Documentation

◆ ATTNULLABLE_INVALID

#define ATTNULLABLE_INVALID   'i' /* constraint exists, marked invalid */

Definition at line 87 of file tupdesc.h.

◆ ATTNULLABLE_UNKNOWN

#define ATTNULLABLE_UNKNOWN   'u' /* constraint exists, validity unknown */

Definition at line 85 of file tupdesc.h.

◆ ATTNULLABLE_UNRESTRICTED

#define ATTNULLABLE_UNRESTRICTED   'f' /* No constraint exists */

Definition at line 84 of file tupdesc.h.

◆ ATTNULLABLE_VALID

#define ATTNULLABLE_VALID   'v' /* valid constraint exists */

Definition at line 86 of file tupdesc.h.

◆ PinTupleDesc

#define PinTupleDesc (   tupdesc)
Value:
do { \
if ((tupdesc)->tdrefcount >= 0) \
IncrTupleDescRefCount(tupdesc); \
} while (0)

Definition at line 213 of file tupdesc.h.

◆ ReleaseTupleDesc

#define ReleaseTupleDesc (   tupdesc)
Value:
do { \
if ((tupdesc)->tdrefcount >= 0) \
DecrTupleDescRefCount(tupdesc); \
} while (0)

Definition at line 219 of file tupdesc.h.

◆ TupleDescAttrAddress

#define TupleDescAttrAddress (   desc)
Value:
(Form_pg_attribute) ((char *) (desc) + \
(offsetof(struct TupleDescData, compact_attrs) + \
(desc)->natts * sizeof(CompactAttribute)))
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202

Definition at line 153 of file tupdesc.h.

◆ TupleDescSize

#define TupleDescSize (   src)
Value:
(offsetof(struct TupleDescData, compact_attrs) + \
(src)->natts * sizeof(CompactAttribute) + \
(src)->natts * sizeof(FormData_pg_attribute))
FormData_pg_attribute
Definition: pg_attribute.h:186

Definition at line 198 of file tupdesc.h.

Typedef Documentation

◆ AttrDefault

typedef struct AttrDefault AttrDefault

◆ CompactAttribute

◆ ConstrCheck

typedef struct ConstrCheck ConstrCheck

◆ TupleConstr

typedef struct TupleConstr TupleConstr

◆ TupleDesc

typedef struct TupleDescData* TupleDesc

Definition at line 145 of file tupdesc.h.

◆ TupleDescData

typedef struct TupleDescData TupleDescData

Function Documentation

◆ BuildDescFromLists()

TupleDesc BuildDescFromLists ( const List names,
const List types,
const List typmods,
const List collations 
)

Definition at line 1044 of file tupdesc.c.

1045{
1046 int natts;
1048 ListCell *l1;
1049 ListCell *l2;
1050 ListCell *l3;
1051 ListCell *l4;
1052 TupleDesc desc;
1053
1054 natts = list_length(names);
1055 Assert(natts == list_length(types));
1056 Assert(natts == list_length(typmods));
1057 Assert(natts == list_length(collations));
1058
1059 /*
1060 * allocate a new tuple descriptor
1061 */
1062 desc = CreateTemplateTupleDesc(natts);
1063
1064 attnum = 0;
1065 forfour(l1, names, l2, types, l3, typmods, l4, collations)
1066 {
1067 char *attname = strVal(lfirst(l1));
1068 Oid atttypid = lfirst_oid(l2);
1069 int32 atttypmod = lfirst_int(l3);
1070 Oid attcollation = lfirst_oid(l4);
1071
1072 attnum++;
1073
1074 TupleDescInitEntry(desc, attnum, attname, atttypid, atttypmod, 0);
1075 TupleDescInitEntryCollation(desc, attnum, attcollation);
1076 }
1077
1078 return desc;
1079}
int16 AttrNumber
Definition: attnum.h:21
int32_t int32
Definition: c.h:498
struct typedefs * types
Definition: ecpg.c:30
Assert(PointerIsAligned(start, uint64))
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:74
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define lfirst_int(lc)
Definition: pg_list.h:173
#define forfour(cell1, list1, cell2, list2, cell3, list3, cell4, list4)
Definition: pg_list.h:575
#define lfirst_oid(lc)
Definition: pg_list.h:174
unsigned int Oid
Definition: postgres_ext.h:30
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:175
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:1019
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:835
#define strVal(v)
Definition: value.h:82

References Assert(), attname, attnum, CreateTemplateTupleDesc(), forfour, lfirst, lfirst_int, lfirst_oid, list_length(), strVal, TupleDescInitEntry(), TupleDescInitEntryCollation(), and types.

Referenced by ExecInitFunctionScan(), ExecInitTableFuncScan(), and inline_set_returning_function().

◆ CreateTemplateTupleDesc()

TupleDesc CreateTemplateTupleDesc ( int  natts)

Definition at line 175 of file tupdesc.c.

176{
177 TupleDesc desc;
178
179 /*
180 * sanity checks
181 */
182 Assert(natts >= 0);
183
184 /*
185 * Allocate enough memory for the tuple descriptor, the CompactAttribute
186 * array and also an array of FormData_pg_attribute.
187 *
188 * Note: the FormData_pg_attribute array stride is
189 * sizeof(FormData_pg_attribute), since we declare the array elements as
190 * FormData_pg_attribute for notational convenience. However, we only
191 * guarantee that the first ATTRIBUTE_FIXED_PART_SIZE bytes of each entry
192 * are valid; most code that copies tupdesc entries around copies just
193 * that much. In principle that could be less due to trailing padding,
194 * although with the current definition of pg_attribute there probably
195 * isn't any padding.
196 */
197 desc = (TupleDesc) palloc(offsetof(struct TupleDescData, compact_attrs) +
198 natts * sizeof(CompactAttribute) +
199 natts * sizeof(FormData_pg_attribute));
200
201 /*
202 * Initialize other fields of the tupdesc.
203 */
204 desc->natts = natts;
205 desc->constr = NULL;
206 desc->tdtypeid = RECORDOID;
207 desc->tdtypmod = -1;
208 desc->tdrefcount = -1; /* assume not reference-counted */
209
210 return desc;
211}
void * palloc(Size size)
Definition: mcxt.c:1317
int tdrefcount
Definition: tupdesc.h:140
TupleConstr * constr
Definition: tupdesc.h:141
int32 tdtypmod
Definition: tupdesc.h:139
Oid tdtypeid
Definition: tupdesc.h:138
struct CompactAttribute CompactAttribute
struct TupleDescData * TupleDesc
Definition: tupdesc.h:145

References Assert(), TupleDescData::constr, FormData_pg_attribute, TupleDescData::natts, palloc(), TupleDescData::tdrefcount, TupleDescData::tdtypeid, and TupleDescData::tdtypmod.

Referenced by aclexplode(), addRangeTableEntryForFunction(), AllocateRelationDesc(), brtuple_disk_tupdesc(), build_function_result_tupdesc_d(), build_row_from_vars(), BuildDescForRelation(), BuildDescFromLists(), BuildHardcodedDescriptor(), ConstructTupleDescriptor(), create_toast_table(), CreateReplicationSlot(), CreateTupleDesc(), CreateTupleDescCopy(), CreateTupleDescCopyConstr(), CreateTupleDescTruncatedCopy(), dblink_get_pkey(), ExecInitFunctionScan(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), ExplainResultDesc(), formrdesc(), get_expr_result_type(), GetPGVariableResultDesc(), gistrescan(), IdentifySystem(), init_sexpr(), initGinState(), injection_points_stats_fixed(), libpqrcv_processTuples(), load_relcache_init_file(), materializeResult(), ordered_set_startup(), pg_buffercache_numa_pages(), pg_buffercache_pages(), pg_get_publication_tables(), pg_get_sequence_data(), pg_lock_status(), pg_prepared_xact(), pg_stat_file(), pg_stat_get_archiver(), pg_stat_get_backend_subxact(), pg_stat_get_replication_slot(), pg_stat_get_subscription_stats(), pg_stat_wal_build_tuple(), pg_visibility_tupdesc(), pg_walfile_name_offset(), ReadReplicationSlot(), SendTablespaceList(), SendTimeLineHistory(), SendXlogRecPtrResult(), show_all_settings(), ShowAllGUCConfig(), ShowGUCConfigOption(), StartReplication(), test_predtest(), tsvector_unnest(), and TypeGetTupleDesc().

◆ CreateTupleDesc()

TupleDesc CreateTupleDesc ( int  natts,
Form_pg_attribute attrs 
)

Definition at line 222 of file tupdesc.c.

223{
224 TupleDesc desc;
225 int i;
226
227 desc = CreateTemplateTupleDesc(natts);
228
229 for (i = 0; i < natts; ++i)
230 {
231 memcpy(TupleDescAttr(desc, i), attrs[i], ATTRIBUTE_FIXED_PART_SIZE);
233 }
234 return desc;
235}
int i
Definition: isn.c:77
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:194
void populate_compact_attribute(TupleDesc tupdesc, int attnum)
Definition: tupdesc.c:117
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160

References ATTRIBUTE_FIXED_PART_SIZE, CreateTemplateTupleDesc(), i, populate_compact_attribute(), and TupleDescAttr().

Referenced by AddNewAttributeTuples(), and InsertOneTuple().

◆ CreateTupleDescCopy()

TupleDesc CreateTupleDescCopy ( TupleDesc  tupdesc)

Definition at line 245 of file tupdesc.c.

246{
247 TupleDesc desc;
248 int i;
249
250 desc = CreateTemplateTupleDesc(tupdesc->natts);
251
252 /* Flat-copy the attribute array */
253 memcpy(TupleDescAttr(desc, 0),
254 TupleDescAttr(tupdesc, 0),
255 desc->natts * sizeof(FormData_pg_attribute));
256
257 /*
258 * Since we're not copying constraints and defaults, clear fields
259 * associated with them.
260 */
261 for (i = 0; i < desc->natts; i++)
262 {
263 Form_pg_attribute att = TupleDescAttr(desc, i);
264
265 att->attnotnull = false;
266 att->atthasdef = false;
267 att->atthasmissing = false;
268 att->attidentity = '\0';
269 att->attgenerated = '\0';
270
272 }
273
274 /* We can copy the tuple type identification, too */
275 desc->tdtypeid = tupdesc->tdtypeid;
276 desc->tdtypmod = tupdesc->tdtypmod;
277
278 return desc;
279}

References CreateTemplateTupleDesc(), FormData_pg_attribute, i, TupleDescData::natts, populate_compact_attribute(), TupleDescData::tdtypeid, TupleDescData::tdtypmod, and TupleDescAttr().

Referenced by assign_record_type_typmod(), BuildTupleHashTable(), cfunc_hashtable_insert(), connectby_text(), connectby_text_serial(), CopyCachedPlan(), crosstab(), crosstab_hash(), database_to_xmlschema_internal(), do_autovacuum(), ExecEvalWholeRowVar(), ExecInitForeignScan(), ExecInitFunctionScan(), ExecInsert(), ExecPrepareTuplestoreResult(), FetchPreparedStatementResultDesc(), fmgr_sql(), get_record_type_from_query(), get_tupdesc_for_join_scan_tuples(), GetAfterTriggersStoreSlot(), getSpGistTupleDesc(), init_sexpr(), InitMaterializedSRF(), make_expanded_record_from_exprecord(), make_expanded_record_from_tupdesc(), materializeResult(), PersistHoldablePortal(), plperl_return_next_internal(), plpgsql_exec_function(), pltcl_func_handler(), PLy_spi_execute_fetch_result(), populate_recordset_worker(), RelationBuildLocalRelation(), RelationNameGetTupleDesc(), RevalidateCachedQuery(), schema_to_xmlschema_internal(), spi_dest_startup(), sql_compile_callback(), storeRow(), update_cached_tupdesc(), and UtilityTupleDescriptor().

◆ CreateTupleDescCopyConstr()

TupleDesc CreateTupleDescCopyConstr ( TupleDesc  tupdesc)

Definition at line 333 of file tupdesc.c.

334{
335 TupleDesc desc;
336 TupleConstr *constr = tupdesc->constr;
337 int i;
338
339 desc = CreateTemplateTupleDesc(tupdesc->natts);
340
341 /* Flat-copy the attribute array */
342 memcpy(TupleDescAttr(desc, 0),
343 TupleDescAttr(tupdesc, 0),
344 desc->natts * sizeof(FormData_pg_attribute));
345
346 for (i = 0; i < desc->natts; i++)
347 {
349
352 }
353
354 /* Copy the TupleConstr data structure, if any */
355 if (constr)
356 {
357 TupleConstr *cpy = (TupleConstr *) palloc0(sizeof(TupleConstr));
358
359 cpy->has_not_null = constr->has_not_null;
362
363 if ((cpy->num_defval = constr->num_defval) > 0)
364 {
365 cpy->defval = (AttrDefault *) palloc(cpy->num_defval * sizeof(AttrDefault));
366 memcpy(cpy->defval, constr->defval, cpy->num_defval * sizeof(AttrDefault));
367 for (i = cpy->num_defval - 1; i >= 0; i--)
368 cpy->defval[i].adbin = pstrdup(constr->defval[i].adbin);
369 }
370
371 if (constr->missing)
372 {
373 cpy->missing = (AttrMissing *) palloc(tupdesc->natts * sizeof(AttrMissing));
374 memcpy(cpy->missing, constr->missing, tupdesc->natts * sizeof(AttrMissing));
375 for (i = tupdesc->natts - 1; i >= 0; i--)
376 {
377 if (constr->missing[i].am_present)
378 {
379 CompactAttribute *attr = TupleDescCompactAttr(tupdesc, i);
380
381 cpy->missing[i].am_value = datumCopy(constr->missing[i].am_value,
382 attr->attbyval,
383 attr->attlen);
384 }
385 }
386 }
387
388 if ((cpy->num_check = constr->num_check) > 0)
389 {
390 cpy->check = (ConstrCheck *) palloc(cpy->num_check * sizeof(ConstrCheck));
391 memcpy(cpy->check, constr->check, cpy->num_check * sizeof(ConstrCheck));
392 for (i = cpy->num_check - 1; i >= 0; i--)
393 {
394 cpy->check[i].ccname = pstrdup(constr->check[i].ccname);
395 cpy->check[i].ccbin = pstrdup(constr->check[i].ccbin);
396 cpy->check[i].ccenforced = constr->check[i].ccenforced;
397 cpy->check[i].ccvalid = constr->check[i].ccvalid;
398 cpy->check[i].ccnoinherit = constr->check[i].ccnoinherit;
399 }
400 }
401
402 desc->constr = cpy;
403 }
404
405 /* We can copy the tuple type identification, too */
406 desc->tdtypeid = tupdesc->tdtypeid;
407 desc->tdtypmod = tupdesc->tdtypmod;
408
409 return desc;
410}
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
char * pstrdup(const char *in)
Definition: mcxt.c:1699
void * palloc0(Size size)
Definition: mcxt.c:1347
char * adbin
Definition: tupdesc.h:25
int16 attlen
Definition: tupdesc.h:71
char attnullability
Definition: tupdesc.h:79
char * ccname
Definition: tupdesc.h:30
bool ccenforced
Definition: tupdesc.h:32
bool ccnoinherit
Definition: tupdesc.h:34
bool ccvalid
Definition: tupdesc.h:33
char * ccbin
Definition: tupdesc.h:31
bool has_generated_virtual
Definition: tupdesc.h:47
bool has_not_null
Definition: tupdesc.h:45
AttrDefault * defval
Definition: tupdesc.h:40
bool has_generated_stored
Definition: tupdesc.h:46
struct AttrMissing * missing
Definition: tupdesc.h:42
ConstrCheck * check
Definition: tupdesc.h:41
uint16 num_defval
Definition: tupdesc.h:43
uint16 num_check
Definition: tupdesc.h:44
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:175

References AttrDefault::adbin, AttrMissing::am_present, AttrMissing::am_value, CompactAttribute::attbyval, CompactAttribute::attlen, CompactAttribute::attnullability, ConstrCheck::ccbin, ConstrCheck::ccenforced, ConstrCheck::ccname, ConstrCheck::ccnoinherit, ConstrCheck::ccvalid, TupleConstr::check, TupleDescData::constr, CreateTemplateTupleDesc(), datumCopy(), TupleConstr::defval, FormData_pg_attribute, TupleConstr::has_generated_stored, TupleConstr::has_generated_virtual, TupleConstr::has_not_null, i, TupleConstr::missing, TupleDescData::natts, TupleConstr::num_check, TupleConstr::num_defval, palloc(), palloc0(), populate_compact_attribute(), pstrdup(), TupleDescData::tdtypeid, TupleDescData::tdtypmod, TupleDescAttr(), and TupleDescCompactAttr().

Referenced by ATGetQueueEntry(), CatalogCacheInitializeCache(), init_tuple_slot(), and lookup_rowtype_tupdesc_copy().

◆ CreateTupleDescTruncatedCopy()

TupleDesc CreateTupleDescTruncatedCopy ( TupleDesc  tupdesc,
int  natts 
)

Definition at line 289 of file tupdesc.c.

290{
291 TupleDesc desc;
292 int i;
293
294 Assert(natts <= tupdesc->natts);
295
296 desc = CreateTemplateTupleDesc(natts);
297
298 /* Flat-copy the attribute array */
299 memcpy(TupleDescAttr(desc, 0),
300 TupleDescAttr(tupdesc, 0),
301 desc->natts * sizeof(FormData_pg_attribute));
302
303 /*
304 * Since we're not copying constraints and defaults, clear fields
305 * associated with them.
306 */
307 for (i = 0; i < desc->natts; i++)
308 {
309 Form_pg_attribute att = TupleDescAttr(desc, i);
310
311 att->attnotnull = false;
312 att->atthasdef = false;
313 att->atthasmissing = false;
314 att->attidentity = '\0';
315 att->attgenerated = '\0';
316
318 }
319
320 /* We can copy the tuple type identification, too */
321 desc->tdtypeid = tupdesc->tdtypeid;
322 desc->tdtypmod = tupdesc->tdtypmod;
323
324 return desc;
325}

References Assert(), CreateTemplateTupleDesc(), FormData_pg_attribute, i, TupleDescData::natts, populate_compact_attribute(), TupleDescData::tdtypeid, TupleDescData::tdtypmod, and TupleDescAttr().

Referenced by gist_page_items(), index_truncate_tuple(), and initGISTstate().

◆ DecrTupleDescRefCount()

void DecrTupleDescRefCount ( TupleDesc  tupdesc)

Definition at line 570 of file tupdesc.c.

571{
572 Assert(tupdesc->tdrefcount > 0);
573
575 if (--tupdesc->tdrefcount == 0)
576 FreeTupleDesc(tupdesc);
577}
ResourceOwner CurrentResourceOwner
Definition: resowner.c:173
void FreeTupleDesc(TupleDesc tupdesc)
Definition: tupdesc.c:495
static void ResourceOwnerForgetTupleDesc(ResourceOwner owner, TupleDesc tupdesc)
Definition: tupdesc.c:55

References Assert(), CurrentResourceOwner, FreeTupleDesc(), ResourceOwnerForgetTupleDesc(), and TupleDescData::tdrefcount.

Referenced by cache_record_field_properties(), and ExecEvalConvertRowtype().

◆ equalRowTypes()

bool equalRowTypes ( TupleDesc  tupdesc1,
TupleDesc  tupdesc2 
)

Definition at line 770 of file tupdesc.c.

771{
772 if (tupdesc1->natts != tupdesc2->natts)
773 return false;
774 if (tupdesc1->tdtypeid != tupdesc2->tdtypeid)
775 return false;
776
777 for (int i = 0; i < tupdesc1->natts; i++)
778 {
779 Form_pg_attribute attr1 = TupleDescAttr(tupdesc1, i);
780 Form_pg_attribute attr2 = TupleDescAttr(tupdesc2, i);
781
782 if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
783 return false;
784 if (attr1->atttypid != attr2->atttypid)
785 return false;
786 if (attr1->atttypmod != attr2->atttypmod)
787 return false;
788 if (attr1->attcollation != attr2->attcollation)
789 return false;
790
791 /* Record types derived from tables could have dropped fields. */
792 if (attr1->attisdropped != attr2->attisdropped)
793 return false;
794 }
795
796 return true;
797}
#define NameStr(name)
Definition: c.h:717

References i, NameStr, TupleDescData::natts, TupleDescData::tdtypeid, and TupleDescAttr().

Referenced by acquire_inherited_sample_rows(), cfunc_match(), ProcedureCreate(), record_type_typmod_compare(), RevalidateCachedQuery(), and shared_record_table_compare().

◆ equalTupleDescs()

bool equalTupleDescs ( TupleDesc  tupdesc1,
TupleDesc  tupdesc2 
)

Definition at line 583 of file tupdesc.c.

584{
585 int i,
586 n;
587
588 if (tupdesc1->natts != tupdesc2->natts)
589 return false;
590 if (tupdesc1->tdtypeid != tupdesc2->tdtypeid)
591 return false;
592
593 /* tdtypmod and tdrefcount are not checked */
594
595 for (i = 0; i < tupdesc1->natts; i++)
596 {
597 Form_pg_attribute attr1 = TupleDescAttr(tupdesc1, i);
598 Form_pg_attribute attr2 = TupleDescAttr(tupdesc2, i);
599
600 /*
601 * We do not need to check every single field here: we can disregard
602 * attrelid and attnum (which were used to place the row in the attrs
603 * array in the first place). It might look like we could dispense
604 * with checking attlen/attbyval/attalign, since these are derived
605 * from atttypid; but in the case of dropped columns we must check
606 * them (since atttypid will be zero for all dropped columns) and in
607 * general it seems safer to check them always.
608 *
609 * We intentionally ignore atthasmissing, since that's not very
610 * relevant in tupdescs, which lack the attmissingval field.
611 */
612 if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
613 return false;
614 if (attr1->atttypid != attr2->atttypid)
615 return false;
616 if (attr1->attlen != attr2->attlen)
617 return false;
618 if (attr1->attndims != attr2->attndims)
619 return false;
620 if (attr1->atttypmod != attr2->atttypmod)
621 return false;
622 if (attr1->attbyval != attr2->attbyval)
623 return false;
624 if (attr1->attalign != attr2->attalign)
625 return false;
626 if (attr1->attstorage != attr2->attstorage)
627 return false;
628 if (attr1->attcompression != attr2->attcompression)
629 return false;
630 if (attr1->attnotnull != attr2->attnotnull)
631 return false;
632
633 /*
634 * When the column has a not-null constraint, we also need to consider
635 * its validity aspect, which only manifests in CompactAttribute->
636 * attnullability, so verify that.
637 */
638 if (attr1->attnotnull)
639 {
640 CompactAttribute *cattr1 = TupleDescCompactAttr(tupdesc1, i);
641 CompactAttribute *cattr2 = TupleDescCompactAttr(tupdesc2, i);
642
646
647 if (cattr1->attnullability != cattr2->attnullability)
648 return false;
649 }
650 if (attr1->atthasdef != attr2->atthasdef)
651 return false;
652 if (attr1->attidentity != attr2->attidentity)
653 return false;
654 if (attr1->attgenerated != attr2->attgenerated)
655 return false;
656 if (attr1->attisdropped != attr2->attisdropped)
657 return false;
658 if (attr1->attislocal != attr2->attislocal)
659 return false;
660 if (attr1->attinhcount != attr2->attinhcount)
661 return false;
662 if (attr1->attcollation != attr2->attcollation)
663 return false;
664 /* variable-length fields are not even present... */
665 }
666
667 if (tupdesc1->constr != NULL)
668 {
669 TupleConstr *constr1 = tupdesc1->constr;
670 TupleConstr *constr2 = tupdesc2->constr;
671
672 if (constr2 == NULL)
673 return false;
674 if (constr1->has_not_null != constr2->has_not_null)
675 return false;
676 if (constr1->has_generated_stored != constr2->has_generated_stored)
677 return false;
678 if (constr1->has_generated_virtual != constr2->has_generated_virtual)
679 return false;
680 n = constr1->num_defval;
681 if (n != (int) constr2->num_defval)
682 return false;
683 /* We assume here that both AttrDefault arrays are in adnum order */
684 for (i = 0; i < n; i++)
685 {
686 AttrDefault *defval1 = constr1->defval + i;
687 AttrDefault *defval2 = constr2->defval + i;
688
689 if (defval1->adnum != defval2->adnum)
690 return false;
691 if (strcmp(defval1->adbin, defval2->adbin) != 0)
692 return false;
693 }
694 if (constr1->missing)
695 {
696 if (!constr2->missing)
697 return false;
698 for (i = 0; i < tupdesc1->natts; i++)
699 {
700 AttrMissing *missval1 = constr1->missing + i;
701 AttrMissing *missval2 = constr2->missing + i;
702
703 if (missval1->am_present != missval2->am_present)
704 return false;
705 if (missval1->am_present)
706 {
707 CompactAttribute *missatt1 = TupleDescCompactAttr(tupdesc1, i);
708
709 if (!datumIsEqual(missval1->am_value, missval2->am_value,
710 missatt1->attbyval, missatt1->attlen))
711 return false;
712 }
713 }
714 }
715 else if (constr2->missing)
716 return false;
717 n = constr1->num_check;
718 if (n != (int) constr2->num_check)
719 return false;
720
721 /*
722 * Similarly, we rely here on the ConstrCheck entries being sorted by
723 * name. If there are duplicate names, the outcome of the comparison
724 * is uncertain, but that should not happen.
725 */
726 for (i = 0; i < n; i++)
727 {
728 ConstrCheck *check1 = constr1->check + i;
729 ConstrCheck *check2 = constr2->check + i;
730
731 if (!(strcmp(check1->ccname, check2->ccname) == 0 &&
732 strcmp(check1->ccbin, check2->ccbin) == 0 &&
733 check1->ccenforced == check2->ccenforced &&
734 check1->ccvalid == check2->ccvalid &&
735 check1->ccnoinherit == check2->ccnoinherit))
736 return false;
737 }
738 }
739 else if (tupdesc2->constr != NULL)
740 return false;
741 return true;
742}
bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
Definition: datum.c:223
AttrNumber adnum
Definition: tupdesc.h:24
#define ATTNULLABLE_UNKNOWN
Definition: tupdesc.h:85

References AttrDefault::adbin, AttrDefault::adnum, AttrMissing::am_present, AttrMissing::am_value, Assert(), CompactAttribute::attbyval, CompactAttribute::attlen, CompactAttribute::attnullability, ATTNULLABLE_UNKNOWN, ConstrCheck::ccbin, ConstrCheck::ccenforced, ConstrCheck::ccname, ConstrCheck::ccnoinherit, ConstrCheck::ccvalid, TupleConstr::check, TupleDescData::constr, datumIsEqual(), TupleConstr::defval, TupleConstr::has_generated_stored, TupleConstr::has_generated_virtual, TupleConstr::has_not_null, i, TupleConstr::missing, NameStr, TupleDescData::natts, TupleConstr::num_check, TupleConstr::num_defval, TupleDescData::tdtypeid, TupleDescAttr(), and TupleDescCompactAttr().

Referenced by RelationFindReplTupleSeq(), and RelationRebuildRelation().

◆ FreeTupleDesc()

void FreeTupleDesc ( TupleDesc  tupdesc)

Definition at line 495 of file tupdesc.c.

496{
497 int i;
498
499 /*
500 * Possibly this should assert tdrefcount == 0, to disallow explicit
501 * freeing of un-refcounted tupdescs?
502 */
503 Assert(tupdesc->tdrefcount <= 0);
504
505 if (tupdesc->constr)
506 {
507 if (tupdesc->constr->num_defval > 0)
508 {
509 AttrDefault *attrdef = tupdesc->constr->defval;
510
511 for (i = tupdesc->constr->num_defval - 1; i >= 0; i--)
512 pfree(attrdef[i].adbin);
513 pfree(attrdef);
514 }
515 if (tupdesc->constr->missing)
516 {
517 AttrMissing *attrmiss = tupdesc->constr->missing;
518
519 for (i = tupdesc->natts - 1; i >= 0; i--)
520 {
521 if (attrmiss[i].am_present
522 && !TupleDescAttr(tupdesc, i)->attbyval)
523 pfree(DatumGetPointer(attrmiss[i].am_value));
524 }
525 pfree(attrmiss);
526 }
527 if (tupdesc->constr->num_check > 0)
528 {
529 ConstrCheck *check = tupdesc->constr->check;
530
531 for (i = tupdesc->constr->num_check - 1; i >= 0; i--)
532 {
533 pfree(check[i].ccname);
534 pfree(check[i].ccbin);
535 }
536 pfree(check);
537 }
538 pfree(tupdesc->constr);
539 }
540
541 pfree(tupdesc);
542}
void pfree(void *pointer)
Definition: mcxt.c:1524
bool attbyval
Definition: pg_attribute.h:94
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317

References Assert(), attbyval, TupleConstr::check, TupleDescData::constr, DatumGetPointer(), TupleConstr::defval, i, TupleConstr::missing, TupleDescData::natts, TupleConstr::num_check, TupleConstr::num_defval, pfree(), TupleDescData::tdrefcount, and TupleDescAttr().

Referenced by AddNewAttributeTuples(), AtEOXact_RelationCache(), cfunc_hashtable_delete(), DecrTupleDescRefCount(), ER_mc_callback(), ExecMakeTableFunctionResult(), ExecPrepareTuplestoreResult(), get_record_type_from_query(), get_rel_sync_entry(), InvalidateCompositeTypeCacheEntry(), ordered_set_startup(), PLy_result_dealloc(), RelationDestroyRelation(), ResOwnerReleaseTupleDesc(), RevalidateCachedQuery(), spgendscan(), update_cached_tupdesc(), and walrcv_clear_result().

◆ hashRowType()

uint32 hashRowType ( TupleDesc  desc)

Definition at line 806 of file tupdesc.c.

807{
808 uint32 s;
809 int i;
810
811 s = hash_combine(0, hash_uint32(desc->natts));
812 s = hash_combine(s, hash_uint32(desc->tdtypeid));
813 for (i = 0; i < desc->natts; ++i)
814 s = hash_combine(s, hash_uint32(TupleDescAttr(desc, i)->atttypid));
815
816 return s;
817}
uint32_t uint32
Definition: c.h:502
static Datum hash_uint32(uint32 k)
Definition: hashfn.h:43
static uint32 hash_combine(uint32 a, uint32 b)
Definition: hashfn.h:68

References hash_combine(), hash_uint32(), i, TupleDescData::natts, TupleDescData::tdtypeid, and TupleDescAttr().

Referenced by cfunc_hash(), record_type_typmod_hash(), and shared_record_table_hash().

◆ IncrTupleDescRefCount()

void IncrTupleDescRefCount ( TupleDesc  tupdesc)

Definition at line 552 of file tupdesc.c.

553{
554 Assert(tupdesc->tdrefcount >= 0);
555
557 tupdesc->tdrefcount++;
559}
void ResourceOwnerEnlarge(ResourceOwner owner)
Definition: resowner.c:452
static void ResourceOwnerRememberTupleDesc(ResourceOwner owner, TupleDesc tupdesc)
Definition: tupdesc.c:49

References Assert(), CurrentResourceOwner, ResourceOwnerEnlarge(), ResourceOwnerRememberTupleDesc(), and TupleDescData::tdrefcount.

Referenced by cache_record_field_properties(), and ExecEvalConvertRowtype().

◆ populate_compact_attribute()

void populate_compact_attribute ( TupleDesc  tupdesc,
int  attnum 
)

Definition at line 117 of file tupdesc.c.

118{
119 Form_pg_attribute src = TupleDescAttr(tupdesc, attnum);
120 CompactAttribute *dst;
121
122 /*
123 * Don't use TupleDescCompactAttr to prevent infinite recursion in assert
124 * builds.
125 */
126 dst = &tupdesc->compact_attrs[attnum];
127
129}
CompactAttribute compact_attrs[FLEXIBLE_ARRAY_MEMBER]
Definition: tupdesc.h:143
static void populate_compact_attribute_internal(Form_pg_attribute src, CompactAttribute *dst)
Definition: tupdesc.c:65

References attnum, TupleDescData::compact_attrs, populate_compact_attribute_internal(), and TupleDescAttr().

Referenced by BuildDescForRelation(), BuildHardcodedDescriptor(), ConstructTupleDescriptor(), CreateTupleDesc(), CreateTupleDescCopy(), CreateTupleDescCopyConstr(), CreateTupleDescTruncatedCopy(), formrdesc(), getSpGistTupleDesc(), load_relcache_init_file(), RelationBuildLocalRelation(), RelationBuildTupleDesc(), TupleDescCopy(), TupleDescCopyEntry(), TupleDescInitBuiltinEntry(), and TupleDescInitEntry().

◆ TupleDescAttr()

static FormData_pg_attribute * TupleDescAttr ( TupleDesc  tupdesc,
int  i 
)
inlinestatic

Definition at line 160 of file tupdesc.h.

161{
163
164 return &attrs[i];
165}
#define TupleDescAttrAddress(desc)
Definition: tupdesc.h:153

References FormData_pg_attribute, i, and TupleDescAttrAddress.

Referenced by AddNewAttributeTuples(), addRangeTableEntryForENR(), AddRelationNewConstraints(), apply_handle_update(), ATAddForeignKeyConstraint(), ATExecAddColumn(), ATExecAddOf(), ATExecAlterColumnType(), ATExecAttachPartition(), ATExecColumnDefault(), ATExecDropNotNull(), ATExecReplicaIdentity(), ATRewriteTable(), attnameAttNum(), attnumAttName(), attnumCollationId(), attnumTypeId(), BeginCopyFrom(), BeginCopyTo(), boot_openrel(), brin_build_desc(), brin_form_tuple(), brin_minmax_add_value(), brin_minmax_multi_add_value(), brin_minmax_multi_union(), brin_minmax_union(), brin_page_items(), bringetbitmap(), bt_normalize_tuple(), build_attrmap_by_name(), build_attrmap_by_position(), build_column_default(), build_generation_expression(), build_index_tlist(), build_physical_tlist(), build_remote_returning(), BuildDescForRelation(), BuildHardcodedDescriptor(), buildNSItemFromTupleDesc(), BuildOnConflictExcludedTargetlist(), buildRelationAliases(), cache_record_field_properties(), CallStmtResultDesc(), CatalogCacheInitializeCache(), CatCacheCopyKeys(), CatCacheFreeKeys(), check_and_init_gencol(), check_exclusion_or_unique_constraint(), check_modified_virtual_generated(), check_selective_binary_conversion(), check_sql_stmt_retval(), CheckAttributeNamesTypes(), CheckAttributeType(), CheckIndexCompatible(), checkInsertTargets(), checkRuleResultList(), CheckVarSlotCompatibility(), checkViewColumns(), CloneFkReferenced(), CloneFkReferencing(), CloneRowTriggersToPartition(), coerce_record_to_complex(), compatConnectbyTupleDescs(), compatCrosstabTupleDescs(), compatible_tupdescs(), composite_to_json(), composite_to_jsonb(), ComputePartitionAttrs(), ConstructTupleDescriptor(), conversion_error_callback(), CopyFromBinaryOneRow(), CopyFromTextLikeOneRow(), CopyGetAttnums(), CopyReadAttributesCSV(), CopyReadAttributesText(), CopyToTextLikeStart(), create_foreign_modify(), create_toast_table(), CreateTriggerFiringOn(), CreateTupleDesc(), CreateTupleDescCopy(), CreateTupleDescCopyConstr(), CreateTupleDescTruncatedCopy(), currtid_for_view(), debugStartup(), debugtup(), DefineIndex(), deparseAnalyzeSql(), deparseInsertSql(), deparseTargetList(), deparseUpdateSql(), DetachPartitionFinalize(), DoCopyTo(), equalRowTypes(), equalTupleDescs(), errtablecol(), examine_attribute(), exec_eval_expr(), exec_move_row_from_fields(), exec_stmt_return_next(), ExecBuildGroupingEqual(), ExecBuildHash32FromAttrs(), ExecBuildParamSetEqual(), ExecBuildProjectionInfo(), ExecBuildSlotValueDescription(), ExecBuildUpdateProjection(), ExecCheckPlanOutput(), ExecComputeStoredGenerated(), ExecConstraints(), ExecEvalFieldSelect(), ExecEvalWholeRowVar(), ExecInitExprRec(), ExecInitGenerated(), ExecInitIndexOnlyScan(), ExecInitTableFuncScan(), ExecScanSubPlan(), ExecSetParamPlan(), ExecSort(), ExecTypeSetColNames(), expand_generated_columns_internal(), expand_insert_targetlist(), expand_single_inheritance_child(), expand_virtual_generated_columns(), expanded_record_lookup_field(), expanded_record_set_tuple(), ExpandRowReference(), expandTableLikeClause(), expandTupleDesc(), find_composite_type_dependencies(), formrdesc(), FreeTupleDesc(), generateClonedIndexStmt(), get_dependent_generated_columns(), get_file_fdw_attribute_options(), get_name_for_var_field(), get_rel_data_width(), get_relation_constraints(), get_rels_with_domain(), get_rte_attribute_is_dropped(), get_rule_expr(), get_simple_values_rte(), get_sql_delete(), get_sql_insert(), get_sql_update(), get_target_list(), get_tupdesc_for_join_scan_tuples(), get_tuple_of_interest(), get_variable(), GetAttributeByName(), getSpGistTupleDesc(), GinBufferInit(), ginFlushBuildState(), gist_page_items(), gistrescan(), hash_record(), hash_record_extended(), hashRowType(), heap_toast_insert_or_update(), heapam_relation_needs_toast_table(), hstore_from_record(), hstore_populate_record(), hypothetical_check_argtypes(), inclusion_get_strategy_procinfo(), index_concurrently_create_copy(), index_form_tuple_context(), initGinState(), initialize_aggregate(), InitializeAttributeOids(), InsertOneNull(), InsertOneValue(), InsertPgAttributeTuples(), intorel_startup(), IsIndexUsableForReplicaIdentityFull(), load_relcache_init_file(), logicalrep_rel_open(), logicalrep_write_attrs(), logicalrep_write_tuple(), make_inh_translation_list(), make_tuple_from_row(), make_tuple_indirect(), map_sql_table_to_xmlschema(), map_sql_typecoll_to_xmlschema_types(), MergeAttributes(), MergeAttributesIntoExisting(), MergeConstraintsIntoExisting(), minmax_get_strategy_procinfo(), minmax_multi_get_strategy_procinfo(), NextCopyFromRawFieldsInternal(), page_header(), ParseComplexProjection(), PartConstraintImpliedByRelConstraint(), pg_get_publication_tables(), pg_prepared_statement(), plperl_build_tuple_result(), plperl_hash_from_tuple(), plperl_modify_tuple(), plpgsql_exec_trigger(), pltcl_build_tuple_argument(), pltcl_build_tuple_result(), pltcl_set_tuple_values(), pltcl_trigger_handler(), PLy_input_setup_tuple(), PLy_modify_tuple(), PLy_output_setup_tuple(), PLy_result_colnames(), PLy_result_coltypes(), PLy_result_coltypmods(), PLyDict_FromTuple(), PLyGenericObject_ToComposite(), PLyMapping_ToComposite(), PLySequence_ToComposite(), populate_compact_attribute(), populate_record(), printsimple(), printsimple_startup(), printtup_prepare_info(), pub_collist_validate(), pub_contains_invalid_column(), pub_form_cols_map(), rebuildInsertSql(), record_cmp(), record_eq(), record_image_cmp(), record_image_eq(), record_in(), record_out(), record_recv(), record_send(), refresh_by_match_merge(), RelationBuildLocalRelation(), RelationBuildPartitionKey(), RelationBuildTupleDesc(), ReorderBufferToastReplace(), ReportNotNullViolationError(), resolve_polymorphic_tupdesc(), rewriteTargetListIU(), rewriteValuesRTE(), ri_ReportViolation(), rowtype_field_matches(), send_relation_and_attrs(), SendRowDescriptionMessage(), serialize_prepare_info(), set_attnotnull(), set_relation_column_names(), slot_fill_defaults(), slot_modify_data(), slot_store_data(), spgGetCache(), SPI_fname(), SPI_fnumber(), SPI_gettype(), SPI_gettypeid(), SPI_getvalue(), SysCacheGetAttrNotNull(), test_predtest(), tfuncInitialize(), tfuncLoadRows(), tlist_matches_tupdesc(), toast_tuple_find_biggest_attribute(), toast_tuple_init(), transformAlterTableStmt(), transformAssignedExpr(), transformIndexConstraint(), transformOfType(), transformTableLikeClause(), triggered_change_notification(), tuple_to_stringinfo(), tupledesc_match(), TupleDescCopy(), TupleDescCopyEntry(), TupleDescGetAttInMetadata(), TupleDescInitBuiltinEntry(), TupleDescInitEntry(), TupleDescInitEntryCollation(), tuples_equal(), tuplesort_begin_index_gin(), TypeGetTupleDesc(), validate_pkattnums(), validateConnectbyTupleDesc(), validateDomainCheckConstraint(), validateDomainNotNullConstraint(), verify_compact_attribute(), verifyPartitionIndexNotNull(), and write_relcache_init_file().

◆ TupleDescCompactAttr()

static CompactAttribute * TupleDescCompactAttr ( TupleDesc  tupdesc,
int  i 
)
inlinestatic

Definition at line 175 of file tupdesc.h.

176{
177 CompactAttribute *cattr = &tupdesc->compact_attrs[i];
178
179#ifdef USE_ASSERT_CHECKING
180
181 /* Check that the CompactAttribute is correctly populated */
182 verify_compact_attribute(tupdesc, i);
183#endif
184
185 return cattr;
186}
void verify_compact_attribute(TupleDesc, int attnum)
Definition: tupdesc.c:142

References TupleDescData::compact_attrs, i, and verify_compact_attribute().

Referenced by _bt_keep_natts_fast(), _bt_preprocess_array_keys(), ATRewriteTable(), brin_deconstruct_tuple(), brin_inclusion_add_value(), brin_inclusion_union(), btestimateparallelscan(), build_attrmap_by_position(), BuildHardcodedDescriptor(), BuildTupleFromCStrings(), check_attrmap_match(), check_domain_for_new_field(), check_sql_stmt_retval(), check_tuple_attribute(), collectMatchBitmap(), convert_prep_stmt_params(), CopyGetAttnums(), CreateTupleDescCopyConstr(), equalTupleDescs(), ER_get_flat_size(), ExecBuildUpdateProjection(), ExecComputeStoredGenerated(), ExecEvalRowNullInt(), ExecEvalWholeRowVar(), ExecInitJunkFilterConversion(), expand_tuple(), expanded_record_set_field_internal(), expanded_record_set_fields(), fastgetattr(), formrdesc(), get_relation_constraints(), get_relation_info(), getDatumCopy(), getmissingattr(), getSpGistTupleDesc(), gistInitBuffering(), heap_attisnull(), heap_attr_equals(), heap_compute_data_size(), heap_deform_tuple(), heap_fill_tuple(), HeapDetermineColumnsInfo(), index_deform_tuple_internal(), index_getattr(), MemoizeHash_equal(), MemoizeHash_hash(), nocache_index_getattr(), nocachegetattr(), PartConstraintImpliedByRelConstraint(), pgoutput_row_filter(), postgresBeginForeignInsert(), postgresPlanForeignModify(), reform_and_rewrite_tuple(), RelationBuildLocalRelation(), RelationBuildTupleDesc(), ri_KeysEqual(), set_attnotnull(), slot_compile_deform(), slot_deform_heap_tuple_internal(), spgdoinsert(), toast_build_flattened_tuple(), toast_delete_external(), toast_flatten_tuple(), toast_flatten_tuple_to_datum(), tstoreReceiveSlot_detoast(), tstoreStartupReceiver(), tts_virtual_materialize(), tuple_data_split_internal(), and ValuesNext().

◆ TupleDescCopy()

void TupleDescCopy ( TupleDesc  dst,
TupleDesc  src 
)

Definition at line 421 of file tupdesc.c.

422{
423 int i;
424
425 /* Flat-copy the header and attribute arrays */
426 memcpy(dst, src, TupleDescSize(src));
427
428 /*
429 * Since we're not copying constraints and defaults, clear fields
430 * associated with them.
431 */
432 for (i = 0; i < dst->natts; i++)
433 {
435
436 att->attnotnull = false;
437 att->atthasdef = false;
438 att->atthasmissing = false;
439 att->attidentity = '\0';
440 att->attgenerated = '\0';
441
443 }
444 dst->constr = NULL;
445
446 /*
447 * Also, assume the destination is not to be ref-counted. (Copying the
448 * source's refcount would be wrong in any case.)
449 */
450 dst->tdrefcount = -1;
451}
#define TupleDescSize(src)
Definition: tupdesc.h:198

References TupleDescData::constr, i, TupleDescData::natts, populate_compact_attribute(), TupleDescData::tdrefcount, TupleDescAttr(), and TupleDescSize.

Referenced by share_tupledesc().

◆ TupleDescCopyEntry()

void TupleDescCopyEntry ( TupleDesc  dst,
AttrNumber  dstAttno,
TupleDesc  src,
AttrNumber  srcAttno 
)

Definition at line 461 of file tupdesc.c.

463{
464 Form_pg_attribute dstAtt = TupleDescAttr(dst, dstAttno - 1);
465 Form_pg_attribute srcAtt = TupleDescAttr(src, srcAttno - 1);
466
467 /*
468 * sanity checks
469 */
472 Assert(srcAttno >= 1);
473 Assert(srcAttno <= src->natts);
474 Assert(dstAttno >= 1);
475 Assert(dstAttno <= dst->natts);
476
477 memcpy(dstAtt, srcAtt, ATTRIBUTE_FIXED_PART_SIZE);
478
479 dstAtt->attnum = dstAttno;
480
481 /* since we're not copying constraints or defaults, clear these */
482 dstAtt->attnotnull = false;
483 dstAtt->atthasdef = false;
484 dstAtt->atthasmissing = false;
485 dstAtt->attidentity = '\0';
486 dstAtt->attgenerated = '\0';
487
488 populate_compact_attribute(dst, dstAttno - 1);
489}
#define PointerIsValid(pointer)
Definition: c.h:734

References Assert(), ATTRIBUTE_FIXED_PART_SIZE, PointerIsValid, populate_compact_attribute(), and TupleDescAttr().

Referenced by addRangeTableEntryForFunction(), ExecInitFunctionScan(), and ordered_set_startup().

◆ TupleDescGetDefault()

Node * TupleDescGetDefault ( TupleDesc  tupdesc,
AttrNumber  attnum 
)

Definition at line 1085 of file tupdesc.c.

1086{
1087 Node *result = NULL;
1088
1089 if (tupdesc->constr)
1090 {
1091 AttrDefault *attrdef = tupdesc->constr->defval;
1092
1093 for (int i = 0; i < tupdesc->constr->num_defval; i++)
1094 {
1095 if (attrdef[i].adnum == attnum)
1096 {
1097 result = stringToNode(attrdef[i].adbin);
1098 break;
1099 }
1100 }
1101 }
1102
1103 return result;
1104}
void * stringToNode(const char *str)
Definition: read.c:90
Definition: nodes.h:135

References attnum, TupleDescData::constr, TupleConstr::defval, i, TupleConstr::num_defval, and stringToNode().

Referenced by build_column_default(), expandTableLikeClause(), and MergeAttributes().

◆ TupleDescInitBuiltinEntry()

void TupleDescInitBuiltinEntry ( TupleDesc  desc,
AttrNumber  attributeNumber,
const char *  attributeName,
Oid  oidtypeid,
int32  typmod,
int  attdim 
)

Definition at line 911 of file tupdesc.c.

917{
919
920 /* sanity checks */
921 Assert(PointerIsValid(desc));
922 Assert(attributeNumber >= 1);
923 Assert(attributeNumber <= desc->natts);
924 Assert(attdim >= 0);
925 Assert(attdim <= PG_INT16_MAX);
926
927 /* initialize the attribute fields */
928 att = TupleDescAttr(desc, attributeNumber - 1);
929 att->attrelid = 0; /* dummy value */
930
931 /* unlike TupleDescInitEntry, we require an attribute name */
932 Assert(attributeName != NULL);
933 namestrcpy(&(att->attname), attributeName);
934
935 att->atttypmod = typmod;
936
937 att->attnum = attributeNumber;
938 att->attndims = attdim;
939
940 att->attnotnull = false;
941 att->atthasdef = false;
942 att->atthasmissing = false;
943 att->attidentity = '\0';
944 att->attgenerated = '\0';
945 att->attisdropped = false;
946 att->attislocal = true;
947 att->attinhcount = 0;
948 /* variable-length fields are not present in tupledescs */
949
950 att->atttypid = oidtypeid;
951
952 /*
953 * Our goal here is to support just enough types to let basic builtin
954 * commands work without catalog access - e.g. so that we can do certain
955 * things even in processes that are not connected to a database.
956 */
957 switch (oidtypeid)
958 {
959 case TEXTOID:
960 case TEXTARRAYOID:
961 att->attlen = -1;
962 att->attbyval = false;
963 att->attalign = TYPALIGN_INT;
964 att->attstorage = TYPSTORAGE_EXTENDED;
965 att->attcompression = InvalidCompressionMethod;
966 att->attcollation = DEFAULT_COLLATION_OID;
967 break;
968
969 case BOOLOID:
970 att->attlen = 1;
971 att->attbyval = true;
972 att->attalign = TYPALIGN_CHAR;
973 att->attstorage = TYPSTORAGE_PLAIN;
974 att->attcompression = InvalidCompressionMethod;
975 att->attcollation = InvalidOid;
976 break;
977
978 case INT4OID:
979 att->attlen = 4;
980 att->attbyval = true;
981 att->attalign = TYPALIGN_INT;
982 att->attstorage = TYPSTORAGE_PLAIN;
983 att->attcompression = InvalidCompressionMethod;
984 att->attcollation = InvalidOid;
985 break;
986
987 case INT8OID:
988 att->attlen = 8;
989 att->attbyval = FLOAT8PASSBYVAL;
990 att->attalign = TYPALIGN_DOUBLE;
991 att->attstorage = TYPSTORAGE_PLAIN;
992 att->attcompression = InvalidCompressionMethod;
993 att->attcollation = InvalidOid;
994 break;
995
996 case OIDOID:
997 att->attlen = 4;
998 att->attbyval = true;
999 att->attalign = TYPALIGN_INT;
1000 att->attstorage = TYPSTORAGE_PLAIN;
1001 att->attcompression = InvalidCompressionMethod;
1002 att->attcollation = InvalidOid;
1003 break;
1004
1005 default:
1006 elog(ERROR, "unsupported type %u", oidtypeid);
1007 }
1008
1009 populate_compact_attribute(desc, attributeNumber - 1);
1010}
#define FLOAT8PASSBYVAL
Definition: c.h:606
#define PG_INT16_MAX
Definition: c.h:557
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
void namestrcpy(Name name, const char *str)
Definition: name.c:233
#define InvalidOid
Definition: postgres_ext.h:35
#define InvalidCompressionMethod

References Assert(), elog, ERROR, FLOAT8PASSBYVAL, InvalidCompressionMethod, InvalidOid, namestrcpy(), PG_INT16_MAX, PointerIsValid, populate_compact_attribute(), and TupleDescAttr().

Referenced by CreateReplicationSlot(), IdentifySystem(), ReadReplicationSlot(), SendTablespaceList(), SendTimeLineHistory(), SendXlogRecPtrResult(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

◆ TupleDescInitEntry()

void TupleDescInitEntry ( TupleDesc  desc,
AttrNumber  attributeNumber,
const char *  attributeName,
Oid  oidtypeid,
int32  typmod,
int  attdim 
)

Definition at line 835 of file tupdesc.c.

841{
842 HeapTuple tuple;
843 Form_pg_type typeForm;
845
846 /*
847 * sanity checks
848 */
849 Assert(PointerIsValid(desc));
850 Assert(attributeNumber >= 1);
851 Assert(attributeNumber <= desc->natts);
852 Assert(attdim >= 0);
853 Assert(attdim <= PG_INT16_MAX);
854
855 /*
856 * initialize the attribute fields
857 */
858 att = TupleDescAttr(desc, attributeNumber - 1);
859
860 att->attrelid = 0; /* dummy value */
861
862 /*
863 * Note: attributeName can be NULL, because the planner doesn't always
864 * fill in valid resname values in targetlists, particularly for resjunk
865 * attributes. Also, do nothing if caller wants to re-use the old attname.
866 */
867 if (attributeName == NULL)
868 MemSet(NameStr(att->attname), 0, NAMEDATALEN);
869 else if (attributeName != NameStr(att->attname))
870 namestrcpy(&(att->attname), attributeName);
871
872 att->atttypmod = typmod;
873
874 att->attnum = attributeNumber;
875 att->attndims = attdim;
876
877 att->attnotnull = false;
878 att->atthasdef = false;
879 att->atthasmissing = false;
880 att->attidentity = '\0';
881 att->attgenerated = '\0';
882 att->attisdropped = false;
883 att->attislocal = true;
884 att->attinhcount = 0;
885 /* variable-length fields are not present in tupledescs */
886
887 tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(oidtypeid));
888 if (!HeapTupleIsValid(tuple))
889 elog(ERROR, "cache lookup failed for type %u", oidtypeid);
890 typeForm = (Form_pg_type) GETSTRUCT(tuple);
891
892 att->atttypid = oidtypeid;
893 att->attlen = typeForm->typlen;
894 att->attbyval = typeForm->typbyval;
895 att->attalign = typeForm->typalign;
896 att->attstorage = typeForm->typstorage;
897 att->attcompression = InvalidCompressionMethod;
898 att->attcollation = typeForm->typcollation;
899
900 populate_compact_attribute(desc, attributeNumber - 1);
901
902 ReleaseSysCache(tuple);
903}
#define MemSet(start, val, len)
Definition: c.h:991
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
#define NAMEDATALEN
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

References Assert(), elog, ERROR, GETSTRUCT(), HeapTupleIsValid, InvalidCompressionMethod, MemSet, NAMEDATALEN, NameStr, namestrcpy(), ObjectIdGetDatum(), PG_INT16_MAX, PointerIsValid, populate_compact_attribute(), ReleaseSysCache(), SearchSysCache1(), and TupleDescAttr().

Referenced by aclexplode(), addRangeTableEntryForFunction(), brtuple_disk_tupdesc(), build_function_result_tupdesc_d(), build_row_from_vars(), BuildDescForRelation(), BuildDescFromLists(), CallStmtResultDesc(), create_toast_table(), dblink_get_pkey(), ExecInitFunctionScan(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), ExplainResultDesc(), get_expr_result_type(), GetPGVariableResultDesc(), gistrescan(), init_sexpr(), initGinState(), injection_points_stats_fixed(), libpqrcv_processTuples(), materializeResult(), ordered_set_startup(), pg_buffercache_numa_pages(), pg_buffercache_pages(), pg_get_publication_tables(), pg_get_sequence_data(), pg_lock_status(), pg_prepared_xact(), pg_stat_file(), pg_stat_get_archiver(), pg_stat_get_backend_subxact(), pg_stat_get_replication_slot(), pg_stat_get_subscription_stats(), pg_stat_wal_build_tuple(), pg_visibility_tupdesc(), pg_walfile_name_offset(), resolve_polymorphic_tupdesc(), show_all_settings(), test_predtest(), tsvector_unnest(), and TypeGetTupleDesc().

◆ TupleDescInitEntryCollation()

void TupleDescInitEntryCollation ( TupleDesc  desc,
AttrNumber  attributeNumber,
Oid  collationid 
)

Definition at line 1019 of file tupdesc.c.

1022{
1023 /*
1024 * sanity checks
1025 */
1026 Assert(PointerIsValid(desc));
1027 Assert(attributeNumber >= 1);
1028 Assert(attributeNumber <= desc->natts);
1029
1030 TupleDescAttr(desc, attributeNumber - 1)->attcollation = collationid;
1031}

References Assert(), PointerIsValid, and TupleDescAttr().

Referenced by addRangeTableEntryForFunction(), build_row_from_vars(), BuildDescForRelation(), BuildDescFromLists(), ExecInitFunctionScan(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), get_expr_result_type(), initGinState(), and resolve_polymorphic_tupdesc().

◆ verify_compact_attribute()

void verify_compact_attribute ( TupleDesc  tupdesc,
int  attnum 
)

Definition at line 142 of file tupdesc.c.

143{
144#ifdef USE_ASSERT_CHECKING
145 CompactAttribute *cattr = &tupdesc->compact_attrs[attnum];
146 Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum);
148
149 /*
150 * Populate the temporary CompactAttribute from the corresponding
151 * Form_pg_attribute
152 */
154
155 /*
156 * Make the attcacheoff match since it's been reset to -1 by
157 * populate_compact_attribute_internal. Same with attnullability.
158 */
159 tmp.attcacheoff = cattr->attcacheoff;
160 tmp.attnullability = cattr->attnullability;
161
162 /* Check the freshly populated CompactAttribute matches the TupleDesc's */
163 Assert(memcmp(&tmp, cattr, sizeof(CompactAttribute)) == 0);
164#endif
165}
int32 attcacheoff
Definition: tupdesc.h:70

References Assert(), CompactAttribute::attcacheoff, CompactAttribute::attnullability, attnum, TupleDescData::compact_attrs, populate_compact_attribute_internal(), and TupleDescAttr().

Referenced by TupleDescCompactAttr().