PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 TupleDescFinalize (TupleDesc tupdesc)
 
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) \
} while (0)
static int fb(int x)

Definition at line 234 of file tupdesc.h.

235 { \
236 if ((tupdesc)->tdrefcount >= 0) \
237 IncrTupleDescRefCount(tupdesc); \
238 } while (0)

◆ ReleaseTupleDesc

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

Definition at line 240 of file tupdesc.h.

241 { \
242 if ((tupdesc)->tdrefcount >= 0) \
243 DecrTupleDescRefCount(tupdesc); \
244 } while (0)

◆ 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 at line 171 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 at line 218 of file tupdesc.h.

Typedef Documentation

◆ AttrDefault

◆ CompactAttribute

◆ ConstrCheck

◆ TupleConstr

◆ TupleDesc

Definition at line 163 of file tupdesc.h.

◆ TupleDescData

Function Documentation

◆ BuildDescFromLists()

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

Definition at line 1118 of file tupdesc.c.

1119{
1120 int natts;
1122 ListCell *l1;
1123 ListCell *l2;
1124 ListCell *l3;
1125 ListCell *l4;
1126 TupleDesc desc;
1127
1128 natts = list_length(names);
1129 Assert(natts == list_length(types));
1130 Assert(natts == list_length(typmods));
1131 Assert(natts == list_length(collations));
1132
1133 /*
1134 * allocate a new tuple descriptor
1135 */
1136 desc = CreateTemplateTupleDesc(natts);
1137
1138 attnum = 0;
1139 forfour(l1, names, l2, types, l3, typmods, l4, collations)
1140 {
1141 char *attname = strVal(lfirst(l1));
1142 Oid atttypid = lfirst_oid(l2);
1143 int32 atttypmod = lfirst_int(l3);
1144 Oid attcollation = lfirst_oid(l4);
1145
1146 attnum++;
1147
1148 TupleDescInitEntry(desc, attnum, attname, atttypid, atttypmod, 0);
1149 TupleDescInitEntryCollation(desc, attnum, attcollation);
1150 }
1151
1152 TupleDescFinalize(desc);
1153
1154 return desc;
1155}
int16 AttrNumber
Definition attnum.h:21
#define Assert(condition)
Definition c.h:943
int32_t int32
Definition c.h:620
struct typedefs * types
Definition ecpg.c:30
NameData attname
int16 attnum
#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:607
#define lfirst_oid(lc)
Definition pg_list.h:174
unsigned int Oid
TupleDesc CreateTemplateTupleDesc(int natts)
Definition tupdesc.c:165
void TupleDescFinalize(TupleDesc tupdesc)
Definition tupdesc.c:511
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition tupdesc.c:1093
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition tupdesc.c:909
#define strVal(v)
Definition value.h:82

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

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

◆ CreateTemplateTupleDesc()

TupleDesc CreateTemplateTupleDesc ( int  natts)
extern

Definition at line 165 of file tupdesc.c.

166{
167 TupleDesc desc;
168
169 /*
170 * sanity checks
171 */
172 Assert(natts >= 0);
173
174 /*
175 * Allocate enough memory for the tuple descriptor, the CompactAttribute
176 * array and also an array of FormData_pg_attribute.
177 *
178 * Note: the FormData_pg_attribute array stride is
179 * sizeof(FormData_pg_attribute), since we declare the array elements as
180 * FormData_pg_attribute for notational convenience. However, we only
181 * guarantee that the first ATTRIBUTE_FIXED_PART_SIZE bytes of each entry
182 * are valid; most code that copies tupdesc entries around copies just
183 * that much. In principle that could be less due to trailing padding,
184 * although with the current definition of pg_attribute there probably
185 * isn't any padding.
186 */
187 desc = (TupleDesc) palloc(offsetof(struct TupleDescData, compact_attrs) +
188 natts * sizeof(CompactAttribute) +
189 natts * sizeof(FormData_pg_attribute));
190
191 /*
192 * Initialize other fields of the tupdesc.
193 */
194 desc->natts = natts;
195 desc->constr = NULL;
196 desc->tdtypeid = RECORDOID;
197 desc->tdtypmod = -1;
198 desc->tdrefcount = -1; /* assume not reference-counted */
199
200 /* This will be set to the correct value by TupleDescFinalize() */
201 desc->firstNonCachedOffsetAttr = -1;
202 desc->firstNonGuaranteedAttr = -1;
203
204 return desc;
205}
void * palloc(Size size)
Definition mcxt.c:1390
int firstNonCachedOffsetAttr
Definition tupdesc.h:154
TupleConstr * constr
Definition tupdesc.h:159
int32 tdtypmod
Definition tupdesc.h:152
int firstNonGuaranteedAttr
Definition tupdesc.h:156
struct TupleDescData * TupleDesc
Definition tupdesc.h:163

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

Referenced by aclexplode(), addRangeTableEntryForFunction(), AllocateRelationDesc(), BeginCopyTo(), brtuple_disk_tupdesc(), build_buffercache_pages_tupledesc(), 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(), libpqrcv_processTuples(), load_relcache_init_file(), materializeQueryResult(), materializeResult(), ordered_set_startup(), pg_buffercache_os_pages_internal(), 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_custom_stats_fixed_report(), test_predtest(), tsvector_unnest(), TypeGetTupleDesc(), and WaitStmtResultDesc().

◆ CreateTupleDesc()

TupleDesc CreateTupleDesc ( int  natts,
Form_pg_attribute attrs 
)
extern

Definition at line 216 of file tupdesc.c.

217{
218 TupleDesc desc;
219 int i;
220
221 desc = CreateTemplateTupleDesc(natts);
222
223 for (i = 0; i < natts; ++i)
224 {
227 }
228
229 TupleDescFinalize(desc);
230
231 return desc;
232}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
int i
Definition isn.c:77
#define ATTRIBUTE_FIXED_PART_SIZE
void populate_compact_attribute(TupleDesc tupdesc, int attnum)
Definition tupdesc.c:100
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:178

References ATTRIBUTE_FIXED_PART_SIZE, CreateTemplateTupleDesc(), fb(), i, memcpy(), populate_compact_attribute(), TupleDescAttr(), and TupleDescFinalize().

Referenced by AddNewAttributeTuples(), and InsertOneTuple().

◆ CreateTupleDescCopy()

TupleDesc CreateTupleDescCopy ( TupleDesc  tupdesc)
extern

Definition at line 242 of file tupdesc.c.

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

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

Referenced by assign_record_type_typmod(), BuildTupleHashTable(), cfunc_hashtable_insert(), CompleteCachedPlan(), 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)
extern

Definition at line 336 of file tupdesc.c.

337{
338 TupleDesc desc;
339 TupleConstr *constr = tupdesc->constr;
340 int i;
341
342 desc = CreateTemplateTupleDesc(tupdesc->natts);
343
344 /* Flat-copy the attribute array (unless there are no attributes) */
345 if (desc->natts > 0)
346 memcpy(TupleDescAttr(desc, 0),
347 TupleDescAttr(tupdesc, 0),
348 desc->natts * sizeof(FormData_pg_attribute));
349
350 for (i = 0; i < desc->natts; i++)
351 {
353
356 }
357
358 /* Copy the TupleConstr data structure, if any */
359 if (constr)
360 {
362
363 cpy->has_not_null = constr->has_not_null;
364 cpy->has_generated_stored = constr->has_generated_stored;
365 cpy->has_generated_virtual = constr->has_generated_virtual;
366
367 if ((cpy->num_defval = constr->num_defval) > 0)
368 {
369 cpy->defval = (AttrDefault *) palloc(cpy->num_defval * sizeof(AttrDefault));
370 memcpy(cpy->defval, constr->defval, cpy->num_defval * sizeof(AttrDefault));
371 for (i = cpy->num_defval - 1; i >= 0; i--)
372 cpy->defval[i].adbin = pstrdup(constr->defval[i].adbin);
373 }
374
375 if (constr->missing)
376 {
377 cpy->missing = (AttrMissing *) palloc(tupdesc->natts * sizeof(AttrMissing));
378 memcpy(cpy->missing, constr->missing, tupdesc->natts * sizeof(AttrMissing));
379 for (i = tupdesc->natts - 1; i >= 0; i--)
380 {
381 if (constr->missing[i].am_present)
382 {
383 CompactAttribute *attr = TupleDescCompactAttr(tupdesc, i);
384
385 cpy->missing[i].am_value = datumCopy(constr->missing[i].am_value,
386 attr->attbyval,
387 attr->attlen);
388 }
389 }
390 }
391
392 if ((cpy->num_check = constr->num_check) > 0)
393 {
394 cpy->check = (ConstrCheck *) palloc(cpy->num_check * sizeof(ConstrCheck));
395 memcpy(cpy->check, constr->check, cpy->num_check * sizeof(ConstrCheck));
396 for (i = cpy->num_check - 1; i >= 0; i--)
397 {
398 cpy->check[i].ccname = pstrdup(constr->check[i].ccname);
399 cpy->check[i].ccbin = pstrdup(constr->check[i].ccbin);
400 cpy->check[i].ccenforced = constr->check[i].ccenforced;
401 cpy->check[i].ccvalid = constr->check[i].ccvalid;
402 cpy->check[i].ccnoinherit = constr->check[i].ccnoinherit;
403 }
404 }
405
406 desc->constr = cpy;
407 }
408
409 /* We can copy the tuple type identification, too */
410 desc->tdtypeid = tupdesc->tdtypeid;
411 desc->tdtypmod = tupdesc->tdtypmod;
412
413 TupleDescFinalize(desc);
414
415 return desc;
416}
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition datum.c:132
#define palloc0_object(type)
Definition fe_memutils.h:90
char * pstrdup(const char *in)
Definition mcxt.c:1910
char * adbin
Definition tupdesc.h:25
char attnullability
Definition tupdesc.h:80
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:195

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, fb(), FormData_pg_attribute, TupleConstr::has_generated_stored, TupleConstr::has_generated_virtual, TupleConstr::has_not_null, i, memcpy(), TupleConstr::missing, TupleDescData::natts, TupleConstr::num_check, TupleConstr::num_defval, palloc(), palloc0_object, populate_compact_attribute(), pstrdup(), TupleDescData::tdtypeid, TupleDescData::tdtypmod, TupleDescAttr(), TupleDescCompactAttr(), and TupleDescFinalize().

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

◆ CreateTupleDescTruncatedCopy()

TupleDesc CreateTupleDescTruncatedCopy ( TupleDesc  tupdesc,
int  natts 
)
extern

Definition at line 289 of file tupdesc.c.

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

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

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

◆ DecrTupleDescRefCount()

void DecrTupleDescRefCount ( TupleDesc  tupdesc)
extern

Definition at line 644 of file tupdesc.c.

645{
646 Assert(tupdesc->tdrefcount > 0);
647
649 if (--tupdesc->tdrefcount == 0)
650 FreeTupleDesc(tupdesc);
651}
ResourceOwner CurrentResourceOwner
Definition resowner.c:173
void FreeTupleDesc(TupleDesc tupdesc)
Definition tupdesc.c:569
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 
)
extern

Definition at line 844 of file tupdesc.c.

845{
846 if (tupdesc1->natts != tupdesc2->natts)
847 return false;
848 if (tupdesc1->tdtypeid != tupdesc2->tdtypeid)
849 return false;
850
851 for (int i = 0; i < tupdesc1->natts; i++)
852 {
855
856 if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
857 return false;
858 if (attr1->atttypid != attr2->atttypid)
859 return false;
860 if (attr1->atttypmod != attr2->atttypmod)
861 return false;
862 if (attr1->attcollation != attr2->attcollation)
863 return false;
864
865 /* Record types derived from tables could have dropped fields. */
866 if (attr1->attisdropped != attr2->attisdropped)
867 return false;
868 }
869
870 return true;
871}
#define NameStr(name)
Definition c.h:835

References fb(), i, NameStr, 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 
)
extern

Definition at line 657 of file tupdesc.c.

658{
659 int i,
660 n;
661
662 if (tupdesc1->natts != tupdesc2->natts)
663 return false;
664 if (tupdesc1->tdtypeid != tupdesc2->tdtypeid)
665 return false;
666
667 /* tdtypmod and tdrefcount are not checked */
668
669 for (i = 0; i < tupdesc1->natts; i++)
670 {
673
674 /*
675 * We do not need to check every single field here: we can disregard
676 * attrelid and attnum (which were used to place the row in the attrs
677 * array in the first place). It might look like we could dispense
678 * with checking attlen/attbyval/attalign, since these are derived
679 * from atttypid; but in the case of dropped columns we must check
680 * them (since atttypid will be zero for all dropped columns) and in
681 * general it seems safer to check them always.
682 *
683 * We intentionally ignore atthasmissing, since that's not very
684 * relevant in tupdescs, which lack the attmissingval field.
685 */
686 if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
687 return false;
688 if (attr1->atttypid != attr2->atttypid)
689 return false;
690 if (attr1->attlen != attr2->attlen)
691 return false;
692 if (attr1->attndims != attr2->attndims)
693 return false;
694 if (attr1->atttypmod != attr2->atttypmod)
695 return false;
696 if (attr1->attbyval != attr2->attbyval)
697 return false;
698 if (attr1->attalign != attr2->attalign)
699 return false;
700 if (attr1->attstorage != attr2->attstorage)
701 return false;
702 if (attr1->attcompression != attr2->attcompression)
703 return false;
704 if (attr1->attnotnull != attr2->attnotnull)
705 return false;
706
707 /*
708 * When the column has a not-null constraint, we also need to consider
709 * its validity aspect, which only manifests in CompactAttribute->
710 * attnullability, so verify that.
711 */
712 if (attr1->attnotnull)
713 {
716
717 Assert(cattr1->attnullability != ATTNULLABLE_UNKNOWN);
718 Assert((cattr1->attnullability == ATTNULLABLE_UNKNOWN) ==
719 (cattr2->attnullability == ATTNULLABLE_UNKNOWN));
720
721 if (cattr1->attnullability != cattr2->attnullability)
722 return false;
723 }
724 if (attr1->atthasdef != attr2->atthasdef)
725 return false;
726 if (attr1->attidentity != attr2->attidentity)
727 return false;
728 if (attr1->attgenerated != attr2->attgenerated)
729 return false;
730 if (attr1->attisdropped != attr2->attisdropped)
731 return false;
732 if (attr1->attislocal != attr2->attislocal)
733 return false;
734 if (attr1->attinhcount != attr2->attinhcount)
735 return false;
736 if (attr1->attcollation != attr2->attcollation)
737 return false;
738 /* variable-length fields are not even present... */
739 }
740
741 if (tupdesc1->constr != NULL)
742 {
743 TupleConstr *constr1 = tupdesc1->constr;
744 TupleConstr *constr2 = tupdesc2->constr;
745
746 if (constr2 == NULL)
747 return false;
748 if (constr1->has_not_null != constr2->has_not_null)
749 return false;
750 if (constr1->has_generated_stored != constr2->has_generated_stored)
751 return false;
752 if (constr1->has_generated_virtual != constr2->has_generated_virtual)
753 return false;
754 n = constr1->num_defval;
755 if (n != (int) constr2->num_defval)
756 return false;
757 /* We assume here that both AttrDefault arrays are in adnum order */
758 for (i = 0; i < n; i++)
759 {
760 AttrDefault *defval1 = constr1->defval + i;
761 AttrDefault *defval2 = constr2->defval + i;
762
763 if (defval1->adnum != defval2->adnum)
764 return false;
765 if (strcmp(defval1->adbin, defval2->adbin) != 0)
766 return false;
767 }
768 if (constr1->missing)
769 {
770 if (!constr2->missing)
771 return false;
772 for (i = 0; i < tupdesc1->natts; i++)
773 {
774 AttrMissing *missval1 = constr1->missing + i;
775 AttrMissing *missval2 = constr2->missing + i;
776
777 if (missval1->am_present != missval2->am_present)
778 return false;
779 if (missval1->am_present)
780 {
782
783 if (!datumIsEqual(missval1->am_value, missval2->am_value,
784 missatt1->attbyval, missatt1->attlen))
785 return false;
786 }
787 }
788 }
789 else if (constr2->missing)
790 return false;
791 n = constr1->num_check;
792 if (n != (int) constr2->num_check)
793 return false;
794
795 /*
796 * Similarly, we rely here on the ConstrCheck entries being sorted by
797 * name. If there are duplicate names, the outcome of the comparison
798 * is uncertain, but that should not happen.
799 */
800 for (i = 0; i < n; i++)
801 {
802 ConstrCheck *check1 = constr1->check + i;
803 ConstrCheck *check2 = constr2->check + i;
804
805 if (!(strcmp(check1->ccname, check2->ccname) == 0 &&
806 strcmp(check1->ccbin, check2->ccbin) == 0 &&
807 check1->ccenforced == check2->ccenforced &&
808 check1->ccvalid == check2->ccvalid &&
809 check1->ccnoinherit == check2->ccnoinherit))
810 return false;
811 }
812 }
813 else if (tupdesc2->constr != NULL)
814 return false;
815 return true;
816}
bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
Definition datum.c:223
#define ATTNULLABLE_UNKNOWN
Definition tupdesc.h:85

References Assert, ATTNULLABLE_UNKNOWN, datumIsEqual(), fb(), i, NameStr, TupleConstr::num_defval, TupleDescAttr(), and TupleDescCompactAttr().

Referenced by RelationFindDeletedTupleInfoByIndex(), RelationFindDeletedTupleInfoSeq(), RelationFindReplTupleSeq(), and RelationRebuildRelation().

◆ FreeTupleDesc()

void FreeTupleDesc ( TupleDesc  tupdesc)
extern

Definition at line 569 of file tupdesc.c.

570{
571 int i;
572
573 /*
574 * Possibly this should assert tdrefcount == 0, to disallow explicit
575 * freeing of un-refcounted tupdescs?
576 */
577 Assert(tupdesc->tdrefcount <= 0);
578
579 if (tupdesc->constr)
580 {
581 if (tupdesc->constr->num_defval > 0)
582 {
583 AttrDefault *attrdef = tupdesc->constr->defval;
584
585 for (i = tupdesc->constr->num_defval - 1; i >= 0; i--)
586 pfree(attrdef[i].adbin);
587 pfree(attrdef);
588 }
589 if (tupdesc->constr->missing)
590 {
591 AttrMissing *attrmiss = tupdesc->constr->missing;
592
593 for (i = tupdesc->natts - 1; i >= 0; i--)
594 {
595 if (attrmiss[i].am_present
596 && !TupleDescAttr(tupdesc, i)->attbyval)
597 pfree(DatumGetPointer(attrmiss[i].am_value));
598 }
600 }
601 if (tupdesc->constr->num_check > 0)
602 {
603 ConstrCheck *check = tupdesc->constr->check;
604
605 for (i = tupdesc->constr->num_check - 1; i >= 0; i--)
606 {
607 pfree(check[i].ccname);
608 pfree(check[i].ccbin);
609 }
610 pfree(check);
611 }
612 pfree(tupdesc->constr);
613 }
614
615 pfree(tupdesc);
616}
void pfree(void *pointer)
Definition mcxt.c:1619
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332

References Assert, TupleConstr::check, TupleDescData::constr, DatumGetPointer(), TupleConstr::defval, fb(), 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(), do_autovacuum(), 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)
extern

Definition at line 880 of file tupdesc.c.

881{
882 uint32 s;
883 int i;
884
885 s = hash_combine(0, hash_bytes_uint32(desc->natts));
887 for (i = 0; i < desc->natts; ++i)
889
890 return s;
891}
uint32_t uint32
Definition c.h:624
uint32 hash_bytes_uint32(uint32 k)
Definition hashfn.c:610
static uint32 hash_combine(uint32 a, uint32 b)
Definition hashfn.h:68

References fb(), hash_bytes_uint32(), hash_combine(), 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)
extern

Definition at line 626 of file tupdesc.c.

627{
628 Assert(tupdesc->tdrefcount >= 0);
629
631 tupdesc->tdrefcount++;
633}
void ResourceOwnerEnlarge(ResourceOwner owner)
Definition resowner.c:449
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 
)
extern

Definition at line 100 of file tupdesc.c.

101{
102 Form_pg_attribute src = TupleDescAttr(tupdesc, attnum);
104
105 /*
106 * Don't use TupleDescCompactAttr to prevent infinite recursion in assert
107 * builds.
108 */
109 dst = &tupdesc->compact_attrs[attnum];
110
112}
CompactAttribute compact_attrs[FLEXIBLE_ARRAY_MEMBER]
Definition tupdesc.h:161
static void populate_compact_attribute_internal(Form_pg_attribute src, CompactAttribute *dst)
Definition tupdesc.c:65

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

Referenced by BuildDescForRelation(), BuildHardcodedDescriptor(), ConstructTupleDescriptor(), create_toast_table(), 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 178 of file tupdesc.h.

179{
181
182 Assert(i >= 0 && i < tupdesc->natts);
183
184 return &attrs[i];
185}
#define TupleDescAttrAddress(desc)
Definition tupdesc.h:171

References Assert, fb(), FormData_pg_attribute, i, TupleDescData::natts, and TupleDescAttrAddress.

Referenced by AddNewAttributeTuples(), addRangeTableEntryForENR(), AddRelationNewConstraints(), 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_remattrmap(), build_remote_returning(), BuildDescForRelation(), BuildHardcodedDescriptor(), buildNSItemFromTupleDesc(), BuildOnConflictExcludedTargetlist(), buildRelationAliases(), cache_record_field_properties(), CallStmtResultDesc(), CatalogCacheInitializeCache(), CatCacheCopyKeys(), 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(), createTableConstraints(), CreateTriggerFiringOn(), CreateTupleDesc(), CreateTupleDescCopy(), CreateTupleDescCopyConstr(), CreateTupleDescTruncatedCopy(), currtid_for_view(), debugStartup(), debugtup(), DefineIndex(), deparseAnalyzeSql(), DetachPartitionFinalize(), DoCopy(), 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_insert_targetlist(), expand_single_inheritance_child(), expand_virtual_generated_columns(), expanded_record_lookup_field(), ExpandRowReference(), expandTableLikeClause(), expandTupleDesc(), find_composite_type_dependencies(), formrdesc(), FreeTupleDesc(), generateClonedIndexStmt(), get_file_fdw_attribute_options(), get_generated_columns(), get_name_for_var_field(), get_rel_data_width(), get_relation_constraints(), get_rels_with_domain(), 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(), getAttributesList(), getSpGistTupleDesc(), GinBufferInit(), 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(), import_spi_query_ok(), inclusion_get_strategy_procinfo(), index_create_copy(), index_form_tuple_context(), initGinState(), initialize_aggregate(), InitializeAttributeOids(), InsertOneNull(), InsertOneValue(), InsertPgAttributeTuples(), intorel_startup(), IsIndexUsableForReplicaIdentityFull(), json_check_mutability(), 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(), populate_compact_attribute(), populate_record(), printsimple(), printsimple_startup(), printtup_prepare_info(), pub_collist_validate(), pub_contains_invalid_column(), pub_form_cols_map(), 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(), 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_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(), transformForPortionOfClause(), transformIndexConstraint(), transformOfType(), transformTableLikeClause(), triggered_change_notification(), tuple_to_stringinfo(), tupledesc_match(), TupleDescCopy(), TupleDescCopyEntry(), TupleDescFinalize(), TupleDescGetAttInMetadata(), TupleDescInitBuiltinEntry(), TupleDescInitEntry(), TupleDescInitEntryCollation(), tuples_equal(), tuplesort_begin_index_gin(), TypeGetTupleDesc(), validateConnectbyTupleDesc(), validateDomainCheckConstraint(), validateDomainNotNullConstraint(), verify_compact_attribute(), verifyPartitionIndexNotNull(), and write_relcache_init_file().

◆ TupleDescCompactAttr()

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

Definition at line 195 of file tupdesc.h.

196{
198
199#ifdef USE_ASSERT_CHECKING
200
201 /* Check that the CompactAttribute is correctly populated */
202 verify_compact_attribute(tupdesc, i);
203#endif
204
205 return cattr;
206}
void verify_compact_attribute(TupleDesc, int attnum)
Definition tupdesc.c:125

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

Referenced by _bt_keep_natts_fast(), _bt_preprocess_array_keys(), adjust_toast_pointers(), apply_handle_update(), ATRewriteTable(), brin_deconstruct_tuple(), brin_inclusion_add_value(), brin_inclusion_union(), btestimateparallelscan(), build_attrmap_by_position(), BuildTupleFromCStrings(), CatCacheFreeKeys(), check_and_init_gencol(), check_attrmap_match(), check_domain_for_new_field(), check_selective_binary_conversion(), check_sql_stmt_retval(), check_tuple_attribute(), collectMatchBitmap(), convert_prep_stmt_params(), CopyGetAttnums(), CreateTupleDescCopyConstr(), deparseInsertSql(), deparseTargetList(), deparseUpdateSql(), equalTupleDescs(), ER_get_flat_size(), ExecBuildUpdateProjection(), ExecComputeStoredGenerated(), ExecEvalRowNullInt(), ExecEvalWholeRowVar(), ExecInitJunkFilterConversion(), expand_tuple(), expanded_record_set_field_internal(), expanded_record_set_fields(), expanded_record_set_tuple(), fastgetattr(), get_dependent_generated_columns(), get_relation_constraints(), get_relation_notnullatts(), get_rte_attribute_is_dropped(), get_rule_expr(), getDatumCopy(), getmissingattr(), ginFlushBuildState(), 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(), PLySequence_ToComposite(), postgresBeginForeignInsert(), postgresPlanForeignModify(), rebuildInsertSql(), reform_tuple(), RelationBuildLocalRelation(), RelationBuildTupleDesc(), ReorderBufferToastReplace(), repack_store_change(), restore_tuple(), ri_KeysEqual(), set_attnotnull(), slot_compile_deform(), slot_fill_defaults(), 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(), TupleDescFinalize(), validate_pkattnums(), ValuesNext(), and var_is_nonnullable().

◆ TupleDescCopy()

void TupleDescCopy ( TupleDesc  dst,
TupleDesc  src 
)
extern

Definition at line 427 of file tupdesc.c.

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

References fb(), i, memcpy(), populate_compact_attribute(), TupleDescAttr(), TupleDescFinalize(), and TupleDescSize.

Referenced by share_tupledesc().

◆ TupleDescCopyEntry()

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

Definition at line 472 of file tupdesc.c.

474{
477
478 /*
479 * sanity checks
480 */
481 Assert(src);
482 Assert(dst);
483 Assert(srcAttno >= 1);
485 Assert(dstAttno >= 1);
487
489
490 dstAtt->attnum = dstAttno;
491
492 /* since we're not copying constraints or defaults, clear these */
493 dstAtt->attnotnull = false;
494 dstAtt->atthasdef = false;
495 dstAtt->atthasmissing = false;
496 dstAtt->attidentity = '\0';
497 dstAtt->attgenerated = '\0';
498
500}

References Assert, ATTRIBUTE_FIXED_PART_SIZE, fb(), memcpy(), populate_compact_attribute(), and TupleDescAttr().

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

◆ TupleDescFinalize()

void TupleDescFinalize ( TupleDesc  tupdesc)
extern

Definition at line 511 of file tupdesc.c.

512{
513 int firstNonCachedOffsetAttr = 0;
514 int firstNonGuaranteedAttr = tupdesc->natts;
515 int off = 0;
516
517 for (int i = 0; i < tupdesc->natts; i++)
518 {
520 Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
521
522 /*
523 * Find the highest attnum which is guaranteed to exist in all tuples
524 * in the table. We currently only pay attention to byval attributes
525 * to allow additional optimizations during tuple deformation.
526 */
527 if (firstNonGuaranteedAttr == tupdesc->natts &&
528 (cattr->attnullability != ATTNULLABLE_VALID || !cattr->attbyval ||
529 cattr->atthasmissing || cattr->attisdropped ||
530 cattr->attlen <= 0 ||
531 attr->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL))
532 firstNonGuaranteedAttr = i;
533
534 /*
535 * Don't cache offsets beyond fixed-width attributes. Virtual
536 * generated attributes are stored as NULLs in the tuple, so we don't
537 * cache offsets beyond these.
538 */
539 if (cattr->attlen <= 0 ||
540 attr->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
541 break;
542
543 off = att_nominal_alignby(off, cattr->attalignby);
544
545 /*
546 * attcacheoff is an int16, so don't try to cache any offsets larger
547 * than will fit in that type. Any attributes which are offset more
548 * than 2^15 are likely due to variable-length attributes. Since we
549 * don't cache offsets for or beyond variable-length attributes, using
550 * an int16 rather than an int32 here is unlikely to cost us anything.
551 */
552 if (off > PG_INT16_MAX)
553 break;
554
555 cattr->attcacheoff = (int16) off;
556
557 off += cattr->attlen;
558 firstNonCachedOffsetAttr = i + 1;
559 }
560
561 tupdesc->firstNonCachedOffsetAttr = firstNonCachedOffsetAttr;
562 tupdesc->firstNonGuaranteedAttr = firstNonGuaranteedAttr;
563}
int16_t int16
Definition c.h:619
#define PG_INT16_MAX
Definition c.h:670
#define ATTNULLABLE_VALID
Definition tupdesc.h:86
#define att_nominal_alignby(cur_offset, attalignby)
Definition tupmacs.h:411

References att_nominal_alignby, ATTNULLABLE_VALID, fb(), TupleDescData::firstNonCachedOffsetAttr, TupleDescData::firstNonGuaranteedAttr, i, TupleDescData::natts, PG_INT16_MAX, TupleDescAttr(), and TupleDescCompactAttr().

Referenced by aclexplode(), addRangeTableEntryForFunction(), BeginCopyTo(), brtuple_disk_tupdesc(), build_buffercache_pages_tupledesc(), build_function_result_tupdesc_d(), build_row_from_vars(), BuildDescForRelation(), BuildDescFromLists(), BuildHardcodedDescriptor(), CallStmtResultDesc(), ConstructTupleDescriptor(), create_toast_table(), CreateReplicationSlot(), CreateTupleDesc(), CreateTupleDescCopy(), CreateTupleDescCopyConstr(), CreateTupleDescTruncatedCopy(), dblink_get_pkey(), DefineRelation(), ExecInitFunctionScan(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), ExplainResultDesc(), formrdesc(), get_expr_result_type(), GetPGVariableResultDesc(), getSpGistTupleDesc(), gistrescan(), IdentifySystem(), init_sexpr(), initGinState(), libpqrcv_processTuples(), load_relcache_init_file(), materializeQueryResult(), materializeResult(), ordered_set_startup(), pg_buffercache_os_pages_internal(), 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(), RelationBuildLocalRelation(), RelationBuildTupleDesc(), resolve_polymorphic_tupdesc(), SendTablespaceList(), SendTimeLineHistory(), SendXlogRecPtrResult(), show_all_settings(), ShowAllGUCConfig(), ShowGUCConfigOption(), StartReplication(), test_custom_stats_fixed_report(), test_predtest(), tsvector_unnest(), TupleDescCopy(), TypeGetTupleDesc(), and WaitStmtResultDesc().

◆ TupleDescGetDefault()

Node * TupleDescGetDefault ( TupleDesc  tupdesc,
AttrNumber  attnum 
)
extern

Definition at line 1161 of file tupdesc.c.

1162{
1163 Node *result = NULL;
1164
1165 if (tupdesc->constr)
1166 {
1167 AttrDefault *attrdef = tupdesc->constr->defval;
1168
1169 for (int i = 0; i < tupdesc->constr->num_defval; i++)
1170 {
1171 if (attrdef[i].adnum == attnum)
1172 {
1173 result = stringToNode(attrdef[i].adbin);
1174 break;
1175 }
1176 }
1177 }
1178
1179 return result;
1180}
uint32 result
void * stringToNode(const char *str)
Definition read.c:90
Definition nodes.h:133

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

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

◆ TupleDescInitBuiltinEntry()

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

Definition at line 985 of file tupdesc.c.

991{
993
994 /* sanity checks */
995 Assert(desc);
998 Assert(attdim >= 0);
1000
1001 /* initialize the attribute fields */
1002 att = TupleDescAttr(desc, attributeNumber - 1);
1003 att->attrelid = 0; /* dummy value */
1004
1005 /* unlike TupleDescInitEntry, we require an attribute name */
1007 namestrcpy(&(att->attname), attributeName);
1008
1009 att->atttypmod = typmod;
1010
1011 att->attnum = attributeNumber;
1012 att->attndims = attdim;
1013
1014 att->attnotnull = false;
1015 att->atthasdef = false;
1016 att->atthasmissing = false;
1017 att->attidentity = '\0';
1018 att->attgenerated = '\0';
1019 att->attisdropped = false;
1020 att->attislocal = true;
1021 att->attinhcount = 0;
1022 /* variable-length fields are not present in tupledescs */
1023
1024 att->atttypid = oidtypeid;
1025
1026 /*
1027 * Our goal here is to support just enough types to let basic builtin
1028 * commands work without catalog access - e.g. so that we can do certain
1029 * things even in processes that are not connected to a database.
1030 */
1031 switch (oidtypeid)
1032 {
1033 case TEXTOID:
1034 case TEXTARRAYOID:
1035 att->attlen = -1;
1036 att->attbyval = false;
1037 att->attalign = TYPALIGN_INT;
1038 att->attstorage = TYPSTORAGE_EXTENDED;
1039 att->attcompression = InvalidCompressionMethod;
1040 att->attcollation = DEFAULT_COLLATION_OID;
1041 break;
1042
1043 case BOOLOID:
1044 att->attlen = 1;
1045 att->attbyval = true;
1046 att->attalign = TYPALIGN_CHAR;
1047 att->attstorage = TYPSTORAGE_PLAIN;
1048 att->attcompression = InvalidCompressionMethod;
1049 att->attcollation = InvalidOid;
1050 break;
1051
1052 case INT4OID:
1053 att->attlen = 4;
1054 att->attbyval = true;
1055 att->attalign = TYPALIGN_INT;
1056 att->attstorage = TYPSTORAGE_PLAIN;
1057 att->attcompression = InvalidCompressionMethod;
1058 att->attcollation = InvalidOid;
1059 break;
1060
1061 case INT8OID:
1062 att->attlen = 8;
1063 att->attbyval = true;
1064 att->attalign = TYPALIGN_DOUBLE;
1065 att->attstorage = TYPSTORAGE_PLAIN;
1066 att->attcompression = InvalidCompressionMethod;
1067 att->attcollation = InvalidOid;
1068 break;
1069
1070 case OIDOID:
1071 att->attlen = 4;
1072 att->attbyval = true;
1073 att->attalign = TYPALIGN_INT;
1074 att->attstorage = TYPSTORAGE_PLAIN;
1075 att->attcompression = InvalidCompressionMethod;
1076 att->attcollation = InvalidOid;
1077 break;
1078
1079 default:
1080 elog(ERROR, "unsupported type %u", oidtypeid);
1081 }
1082
1084}
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
void namestrcpy(Name name, const char *str)
Definition name.c:233
#define InvalidOid
#define InvalidCompressionMethod

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

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

◆ TupleDescInitEntry()

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

Definition at line 909 of file tupdesc.c.

915{
916 HeapTuple tuple;
919
920 /*
921 * sanity checks
922 */
923 Assert(desc);
926 Assert(attdim >= 0);
928
929 /*
930 * initialize the attribute fields
931 */
932 att = TupleDescAttr(desc, attributeNumber - 1);
933
934 att->attrelid = 0; /* dummy value */
935
936 /*
937 * Note: attributeName can be NULL, because the planner doesn't always
938 * fill in valid resname values in targetlists, particularly for resjunk
939 * attributes. Also, do nothing if caller wants to re-use the old attname.
940 */
941 if (attributeName == NULL)
942 MemSet(NameStr(att->attname), 0, NAMEDATALEN);
943 else if (attributeName != NameStr(att->attname))
944 namestrcpy(&(att->attname), attributeName);
945
946 att->atttypmod = typmod;
947
948 att->attnum = attributeNumber;
949 att->attndims = attdim;
950
951 att->attnotnull = false;
952 att->atthasdef = false;
953 att->atthasmissing = false;
954 att->attidentity = '\0';
955 att->attgenerated = '\0';
956 att->attisdropped = false;
957 att->attislocal = true;
958 att->attinhcount = 0;
959 /* variable-length fields are not present in tupledescs */
960
962 if (!HeapTupleIsValid(tuple))
963 elog(ERROR, "cache lookup failed for type %u", oidtypeid);
965
966 att->atttypid = oidtypeid;
967 att->attlen = typeForm->typlen;
968 att->attbyval = typeForm->typbyval;
969 att->attalign = typeForm->typalign;
970 att->attstorage = typeForm->typstorage;
971 att->attcompression = InvalidCompressionMethod;
972 att->attcollation = typeForm->typcollation;
973
975
976 ReleaseSysCache(tuple);
977}
#define MemSet(start, val, len)
Definition c.h:1107
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
#define NAMEDATALEN
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
Definition pg_type.h:265
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221

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

Referenced by aclexplode(), addRangeTableEntryForFunction(), BeginCopyTo(), brtuple_disk_tupdesc(), build_buffercache_pages_tupledesc(), 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(), libpqrcv_processTuples(), materializeQueryResult(), materializeResult(), ordered_set_startup(), pg_buffercache_os_pages_internal(), 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_custom_stats_fixed_report(), test_predtest(), tsvector_unnest(), and TypeGetTupleDesc().

◆ TupleDescInitEntryCollation()

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

◆ verify_compact_attribute()

void verify_compact_attribute ( TupleDesc  tupdesc,
int  attnum 
)
extern

Definition at line 125 of file tupdesc.c.

126{
127#ifdef USE_ASSERT_CHECKING
129 Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum);
131
132 /*
133 * Make a temp copy of the TupleDesc's CompactAttribute. This may be a
134 * shared TupleDesc and the attcacheoff might get changed by another
135 * backend.
136 */
137 memcpy(&cattr, &tupdesc->compact_attrs[attnum], sizeof(CompactAttribute));
138
139 /*
140 * Populate the temporary CompactAttribute from the corresponding
141 * Form_pg_attribute
142 */
144
145 /*
146 * Make the attcacheoff match since it's been reset to -1 by
147 * populate_compact_attribute_internal. Same with attnullability.
148 */
149 tmp.attcacheoff = cattr.attcacheoff;
150 tmp.attnullability = cattr.attnullability;
151
152 /* Check the freshly populated CompactAttribute matches the TupleDesc's */
153 Assert(memcmp(&tmp, &cattr, sizeof(CompactAttribute)) == 0);
154#endif
155}
int16 attcacheoff
Definition tupdesc.h:70

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

Referenced by TupleDescCompactAttr().