PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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  tupleDesc
 

Macros

#define TupleDescAttr(tupdesc, i)   (&(tupdesc)->attrs[(i)])
 
#define TupleDescSize(src)
 
#define PinTupleDesc(tupdesc)
 
#define ReleaseTupleDesc(tupdesc)
 

Typedefs

typedef struct attrDefault AttrDefault
 
typedef struct constrCheck ConstrCheck
 
typedef struct tupleConstr TupleConstr
 
typedef struct tupleDescTupleDesc
 

Functions

TupleDesc CreateTemplateTupleDesc (int natts, bool hasoid)
 
TupleDesc CreateTupleDesc (int natts, bool hasoid, Form_pg_attribute *attrs)
 
TupleDesc CreateTupleDescCopy (TupleDesc tupdesc)
 
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)
 
uint32 hashTupleDesc (TupleDesc tupdesc)
 
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 BuildDescForRelation (List *schema)
 
TupleDesc BuildDescFromLists (List *names, List *types, List *typmods, List *collations)
 

Macro Definition Documentation

#define PinTupleDesc (   tupdesc)
Value:
do { \
if ((tupdesc)->tdrefcount >= 0) \
} while (0)
void IncrTupleDescRefCount(TupleDesc tupdesc)
Definition: tupdesc.c:301

Definition at line 109 of file tupdesc.h.

Referenced by ExecSetSlotDescriptor(), lookup_rowtype_tupdesc(), and lookup_rowtype_tupdesc_noerror().

#define TupleDescAttr (   tupdesc,
  i 
)    (&(tupdesc)->attrs[(i)])

Definition at line 84 of file tupdesc.h.

Referenced by AddNewAttributeTuples(), addRangeTableEntryForENR(), AddRelationNewConstraints(), AlterDomainNotNull(), AppendAttributeTuples(), ATAddForeignKeyConstraint(), ATExecAddOf(), ATExecAlterColumnType(), ATExecAttachPartition(), ATExecDropNotNull(), ATExecReplicaIdentity(), ATRewriteTable(), attnameAttNum(), attnumAttName(), attnumCollationId(), attnumTypeId(), AttrDefaultFetch(), BeginCopy(), BeginCopyFrom(), boot_openrel(), brin_build_desc(), brin_deconstruct_tuple(), brin_inclusion_add_value(), brin_inclusion_union(), brin_minmax_add_value(), brin_minmax_union(), brinbuildCallback(), bringetbitmap(), build_column_default(), build_index_tlist(), build_physical_tlist(), build_row_from_class(), BuildDescForRelation(), BuildHardcodedDescriptor(), buildRelationAliases(), BuildTupleFromCStrings(), cache_record_field_properties(), CatalogCacheInitializeCache(), CatCacheCopyKeys(), CatCacheFreeKeys(), check_selective_binary_conversion(), check_sql_fn_retval(), CheckAttributeNamesTypes(), CheckAttributeType(), CheckIndexCompatible(), checkInsertTargets(), checkRuleResultList(), CheckVarSlotCompatibility(), checkViewTupleDesc(), coerce_record_to_complex(), collectMatchBitmap(), compatConnectbyTupleDescs(), compatCrosstabTupleDescs(), composite_to_json(), composite_to_jsonb(), ConstructTupleDescriptor(), conversion_error_callback(), convert_tuples_by_name(), convert_tuples_by_name_map(), convert_tuples_by_position(), CopyGetAttnums(), CopyTo(), create_toast_table(), CreateTupleDesc(), CreateTupleDescCopy(), CreateTupleDescCopyConstr(), currtid_for_view(), debugStartup(), debugtup(), DefineRelation(), deparseAnalyzeSql(), deparseTargetList(), equalTupleDescs(), errtablecol(), examine_attribute(), exec_assign_value(), exec_eval_datum(), exec_eval_expr(), exec_move_row(), exec_stmt_return_next(), ExecBuildProjectionInfo(), ExecBuildSlotValueDescription(), ExecCheckPlanOutput(), ExecConstraints(), ExecEvalFieldSelect(), ExecEvalRowNullInt(), ExecEvalWholeRowVar(), ExecInitExprRec(), ExecInitJunkFilterConversion(), ExecInitTableFuncScan(), ExecScanSubPlan(), ExecSetParamPlan(), ExecTypeSetColNames(), expand_targetlist(), ExpandRowReference(), expandTupleDesc(), find_composite_type_dependencies(), formrdesc(), generateClonedIndexStmt(), 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_rte_attribute_type(), get_rule_expr(), get_sql_delete(), get_sql_insert(), get_sql_update(), get_target_list(), get_tuple_of_interest(), GetAttributeByName(), getDatumCopy(), gistInitBuffering(), hashTupleDesc(), heap_compute_data_size(), heap_deform_tuple(), heap_fill_tuple(), heap_tuple_attr_equals(), hstore_from_record(), hstore_populate_record(), hypothetical_check_argtypes(), inclusion_get_strategy_procinfo(), index_form_tuple(), initGinState(), initialize_aggregate(), InitializeAttributeOids(), InsertOneNull(), InsertOneValue(), intorel_startup(), 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(), minmax_get_strategy_procinfo(), needs_toast_table(), NextCopyFrom(), nocache_index_getattr(), nocachegetattr(), page_header(), ParseComplexProjection(), PartConstraintImpliedByRelConstraint(), pg_config(), pgoutput_change(), plperl_build_tuple_result(), plperl_hash_from_tuple(), plperl_modify_tuple(), plpgsql_exec_get_datum_type_info(), pltcl_build_tuple_argument(), pltcl_set_tuple_values(), pltcl_trigger_handler(), PLy_input_tuple_funcs(), PLy_modify_tuple(), PLy_output_tuple_funcs(), PLy_result_colnames(), PLy_result_coltypes(), PLy_result_coltypmods(), PLyDict_FromTuple(), PLyGenericObject_ToComposite(), PLyMapping_ToComposite(), PLySequence_ToComposite(), populate_record(), postgresBeginForeignModify(), postgresPlanForeignModify(), printsimple(), printsimple_startup(), printtup_prepare_info(), record_cmp(), record_eq(), record_image_cmp(), record_image_eq(), record_in(), record_out(), record_recv(), record_send(), reform_and_rewrite_tuple(), refresh_by_match_merge(), RelationBuildLocalRelation(), RelationBuildPartitionKey(), RelationBuildTupleDesc(), ReorderBufferToastReplace(), resolve_polymorphic_tupdesc(), rewriteTargetListIU(), rewriteValuesRTE(), rowtype_field_matches(), SendRowDescriptionCols_2(), SendRowDescriptionCols_3(), set_relation_column_names(), slot_deform_tuple(), slot_fill_defaults(), slot_getattr(), slot_modify_cstrings(), slot_store_cstrings(), spgGetCache(), SPI_fname(), SPI_fnumber(), SPI_gettype(), SPI_gettypeid(), SPI_getvalue(), tfuncInitialize(), tfuncLoadRows(), timetravel(), tlist_matches_tupdesc(), toast_build_flattened_tuple(), toast_delete(), toast_flatten_tuple(), toast_flatten_tuple_to_datum(), toast_insert_or_update(), transformAssignedExpr(), transformIndexConstraint(), transformOfType(), transformOnConflictClause(), transformTableLikeClause(), triggered_change_notification(), tstoreReceiveSlot_detoast(), tstoreStartupReceiver(), tuple_data_split_internal(), tuple_equals_slot(), tuple_to_stringinfo(), tupledesc_match(), TupleDescCopyEntry(), TupleDescGetAttInMetadata(), TupleDescInitBuiltinEntry(), TupleDescInitEntry(), TupleDescInitEntryCollation(), TypeGetTupleDesc(), validate_pkattnums(), validateConnectbyTupleDesc(), validateDomainConstraint(), ValuesNext(), and write_relcache_init_file().

#define TupleDescSize (   src)
Value:
(offsetof(struct tupleDesc, attrs) + \
(src)->natts * sizeof(FormData_pg_attribute))
FormData_pg_attribute
Definition: pg_attribute.h:171
#define offsetof(type, field)
Definition: c.h:549

Definition at line 95 of file tupdesc.h.

Referenced by share_tupledesc(), and TupleDescCopy().

Typedef Documentation

Function Documentation

TupleDesc BuildDescForRelation ( List schema)

Definition at line 689 of file tupdesc.c.

References ACL_USAGE, aclcheck_error_type(), ACLCHECK_OK, TypeName::arrayBounds, tupleConstr::check, ColumnDef::colname, tupleDesc::constr, CreateTemplateTupleDesc(), tupleConstr::defval, ereport, errcode(), errmsg(), ERROR, GetColumnDefCollation(), GetUserId(), tupleConstr::has_not_null, ColumnDef::inhcount, ColumnDef::is_local, ColumnDef::is_not_null, lfirst, list_length(), tupleConstr::num_check, tupleConstr::num_defval, palloc0(), pg_type_aclcheck(), TypeName::setof, ColumnDef::storage, TupleDescAttr, TupleDescInitEntry(), TupleDescInitEntryCollation(), ColumnDef::typeName, and typenameTypeIdAndMod().

Referenced by DefineRelation(), and DefineVirtualRelation().

690 {
691  int natts;
692  AttrNumber attnum;
693  ListCell *l;
694  TupleDesc desc;
695  bool has_not_null;
696  char *attname;
697  Oid atttypid;
698  int32 atttypmod;
699  Oid attcollation;
700  int attdim;
701 
702  /*
703  * allocate a new tuple descriptor
704  */
705  natts = list_length(schema);
706  desc = CreateTemplateTupleDesc(natts, false);
707  has_not_null = false;
708 
709  attnum = 0;
710 
711  foreach(l, schema)
712  {
713  ColumnDef *entry = lfirst(l);
714  AclResult aclresult;
715  Form_pg_attribute att;
716 
717  /*
718  * for each entry in the list, get the name and type information from
719  * the list and have TupleDescInitEntry fill in the attribute
720  * information we need.
721  */
722  attnum++;
723 
724  attname = entry->colname;
725  typenameTypeIdAndMod(NULL, entry->typeName, &atttypid, &atttypmod);
726 
727  aclresult = pg_type_aclcheck(atttypid, GetUserId(), ACL_USAGE);
728  if (aclresult != ACLCHECK_OK)
729  aclcheck_error_type(aclresult, atttypid);
730 
731  attcollation = GetColumnDefCollation(NULL, entry, atttypid);
732  attdim = list_length(entry->typeName->arrayBounds);
733 
734  if (entry->typeName->setof)
735  ereport(ERROR,
736  (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
737  errmsg("column \"%s\" cannot be declared SETOF",
738  attname)));
739 
740  TupleDescInitEntry(desc, attnum, attname,
741  atttypid, atttypmod, attdim);
742  att = TupleDescAttr(desc, attnum - 1);
743 
744  /* Override TupleDescInitEntry's settings as requested */
745  TupleDescInitEntryCollation(desc, attnum, attcollation);
746  if (entry->storage)
747  att->attstorage = entry->storage;
748 
749  /* Fill in additional stuff not handled by TupleDescInitEntry */
750  att->attnotnull = entry->is_not_null;
751  has_not_null |= entry->is_not_null;
752  att->attislocal = entry->is_local;
753  att->attinhcount = entry->inhcount;
754  }
755 
756  if (has_not_null)
757  {
758  TupleConstr *constr = (TupleConstr *) palloc0(sizeof(TupleConstr));
759 
760  constr->has_not_null = true;
761  constr->defval = NULL;
762  constr->num_defval = 0;
763  constr->check = NULL;
764  constr->num_check = 0;
765  desc->constr = constr;
766  }
767  else
768  {
769  desc->constr = NULL;
770  }
771 
772  return desc;
773 }
char storage
Definition: parsenodes.h:646
bool is_local
Definition: parsenodes.h:642
Oid GetUserId(void)
Definition: miscinit.c:284
ConstrCheck * check
Definition: tupdesc.h:40
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
int errcode(int sqlerrcode)
Definition: elog.c:575
bool is_not_null
Definition: parsenodes.h:643
unsigned int Oid
Definition: postgres_ext.h:31
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3457
signed int int32
Definition: c.h:246
AttrDefault * defval
Definition: tupdesc.h:39
#define ERROR
Definition: elog.h:43
bool setof
Definition: parsenodes.h:210
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:664
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define ACL_USAGE
Definition: parsenodes.h:80
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
#define ereport(elevel, rest)
Definition: elog.h:122
bool has_not_null
Definition: tupdesc.h:43
Oid GetColumnDefCollation(ParseState *pstate, ColumnDef *coldef, Oid typeOid)
Definition: parse_type.c:521
void * palloc0(Size size)
Definition: mcxt.c:877
AclResult
Definition: acl.h:178
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Definition: parse_type.c:293
uint16 num_defval
Definition: tupdesc.h:41
#define lfirst(lc)
Definition: pg_list.h:106
TupleConstr * constr
Definition: tupdesc.h:78
static int list_length(const List *l)
Definition: pg_list.h:89
TypeName * typeName
Definition: parsenodes.h:640
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
List * arrayBounds
Definition: parsenodes.h:214
int errmsg(const char *fmt,...)
Definition: elog.c:797
int inhcount
Definition: parsenodes.h:641
uint16 num_check
Definition: tupdesc.h:42
char * colname
Definition: parsenodes.h:639
AclResult pg_type_aclcheck(Oid type_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4534
int16 AttrNumber
Definition: attnum.h:21
TupleDesc BuildDescFromLists ( List names,
List types,
List typmods,
List collations 
)

Definition at line 787 of file tupdesc.c.

References Assert, CreateTemplateTupleDesc(), lfirst, lfirst_int, lfirst_oid, list_head(), list_length(), lnext, strVal, TupleDescInitEntry(), and TupleDescInitEntryCollation().

Referenced by ExecInitFunctionScan(), and ExecInitTableFuncScan().

788 {
789  int natts;
790  AttrNumber attnum;
791  ListCell *l1;
792  ListCell *l2;
793  ListCell *l3;
794  ListCell *l4;
795  TupleDesc desc;
796 
797  natts = list_length(names);
798  Assert(natts == list_length(types));
799  Assert(natts == list_length(typmods));
800  Assert(natts == list_length(collations));
801 
802  /*
803  * allocate a new tuple descriptor
804  */
805  desc = CreateTemplateTupleDesc(natts, false);
806 
807  attnum = 0;
808 
809  l2 = list_head(types);
810  l3 = list_head(typmods);
811  l4 = list_head(collations);
812  foreach(l1, names)
813  {
814  char *attname = strVal(lfirst(l1));
815  Oid atttypid;
816  int32 atttypmod;
817  Oid attcollation;
818 
819  atttypid = lfirst_oid(l2);
820  l2 = lnext(l2);
821  atttypmod = lfirst_int(l3);
822  l3 = lnext(l3);
823  attcollation = lfirst_oid(l4);
824  l4 = lnext(l4);
825 
826  attnum++;
827 
828  TupleDescInitEntry(desc, attnum, attname, atttypid, atttypmod, 0);
829  TupleDescInitEntryCollation(desc, attnum, attcollation);
830  }
831 
832  return desc;
833 }
#define strVal(v)
Definition: value.h:54
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:246
#define lfirst_int(lc)
Definition: pg_list.h:107
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:664
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:505
#define lnext(lc)
Definition: pg_list.h:105
#define Assert(condition)
Definition: c.h:681
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
int16 AttrNumber
Definition: attnum.h:21
#define lfirst_oid(lc)
Definition: pg_list.h:108
TupleDesc CreateTemplateTupleDesc ( int  natts,
bool  hasoid 
)

Definition at line 43 of file tupdesc.c.

References AssertArg, tupleDesc::constr, FormData_pg_attribute, tupleDesc::natts, offsetof, palloc(), RECORDOID, tupleDesc::tdhasoid, tupleDesc::tdrefcount, tupleDesc::tdtypeid, and tupleDesc::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(), dblink_get_notify(), dblink_get_pkey(), ExecInitFunctionScan(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), ExplainResultDesc(), formrdesc(), GetPGVariableResultDesc(), gistrescan(), IdentifySystem(), init_sexpr(), initGinState(), libpqrcv_processTuples(), load_relcache_init_file(), materializeQueryResult(), materializeResult(), ordered_set_startup(), pg_buffercache_pages(), pg_control_checkpoint(), pg_control_init(), pg_control_recovery(), pg_control_system(), pg_cursor(), pg_get_keywords(), pg_get_multixact_members(), pg_get_object_address(), pg_identify_object(), pg_identify_object_as_address(), pg_last_committed_xact(), pg_lock_status(), pg_logdir_ls(), pg_ls_dir_files(), pg_prepared_statement(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_archiver(), pg_timezone_abbrevs(), pg_timezone_names(), pg_visibility_map_summary(), pg_visibility_tupdesc(), pg_walfile_name_offset(), prs_setup_firstcall(), show_all_file_settings(), show_all_settings(), ShowAllGUCConfig(), ShowGUCConfigOption(), StartReplication(), ts_setup_firstcall(), tsvector_unnest(), tt_setup_firstcall(), and TypeGetTupleDesc().

44 {
45  TupleDesc desc;
46 
47  /*
48  * sanity checks
49  */
50  AssertArg(natts >= 0);
51 
52  /*
53  * Allocate enough memory for the tuple descriptor, including the
54  * attribute rows.
55  */
56  desc = (TupleDesc) palloc(offsetof(struct tupleDesc, attrs) +
57  natts * sizeof(FormData_pg_attribute));
58 
59  /*
60  * Initialize other fields of the tupdesc.
61  */
62  desc->natts = natts;
63  desc->constr = NULL;
64  desc->tdtypeid = RECORDOID;
65  desc->tdtypmod = -1;
66  desc->tdhasoid = hasoid;
67  desc->tdrefcount = -1; /* assume not reference-counted */
68 
69  return desc;
70 }
Oid tdtypeid
Definition: tupdesc.h:74
bool tdhasoid
Definition: tupdesc.h:76
int natts
Definition: tupdesc.h:73
int32 tdtypmod
Definition: tupdesc.h:75
#define RECORDOID
Definition: pg_type.h:680
#define AssertArg(condition)
Definition: c.h:683
FormData_pg_attribute
Definition: pg_attribute.h:171
struct tupleDesc * TupleDesc
TupleConstr * constr
Definition: tupdesc.h:78
void * palloc(Size size)
Definition: mcxt.c:848
int tdrefcount
Definition: tupdesc.h:77
#define offsetof(type, field)
Definition: c.h:549
TupleDesc CreateTupleDesc ( int  natts,
bool  hasoid,
Form_pg_attribute attrs 
)

Definition at line 81 of file tupdesc.c.

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

Referenced by InsertOneTuple().

82 {
83  TupleDesc desc;
84  int i;
85 
86  desc = CreateTemplateTupleDesc(natts, hasoid);
87 
88  for (i = 0; i < natts; ++i)
89  memcpy(TupleDescAttr(desc, i), attrs[i], ATTRIBUTE_FIXED_PART_SIZE);
90 
91  return desc;
92 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
int i
TupleDesc CreateTupleDescCopy ( TupleDesc  tupdesc)

Definition at line 102 of file tupdesc.c.

References ATTRIBUTE_FIXED_PART_SIZE, tupleDesc::attrs, CreateTemplateTupleDesc(), i, tupleDesc::natts, tupleDesc::tdhasoid, tupleDesc::tdtypeid, tupleDesc::tdtypmod, and TupleDescAttr.

Referenced by assign_record_type_typmod(), ATGetQueueEntry(), build_row_from_class(), check_default_allows_bound(), check_sql_fn_retval(), connectby_text(), connectby_text_serial(), CopyCachedPlan(), crosstab(), crosstab_hash(), database_to_xmlschema_internal(), deflist_to_tuplestore(), do_autovacuum(), each_worker(), each_worker_jsonb(), elements_worker(), elements_worker_jsonb(), exec_move_row(), exec_stmt_return(), ExecEvalWholeRowVar(), ExecInitFunctionScan(), ExecPrepareTuplestoreResult(), FetchPreparedStatementResultDesc(), fmgr_sql(), init_sexpr(), LookupTupleHashEntry(), materializeResult(), PersistHoldablePortal(), pg_config(), plperl_return_next_internal(), plpgsql_exec_function(), pltcl_func_handler(), PLy_spi_execute_fetch_result(), populate_composite(), populate_recordset_worker(), RelationBuildLocalRelation(), RelationNameGetTupleDesc(), RevalidateCachedQuery(), schema_to_xmlschema_internal(), spi_dest_startup(), storeRow(), UtilityTupleDescriptor(), and xpath_table().

103 {
104  TupleDesc desc;
105  int i;
106 
107  desc = CreateTemplateTupleDesc(tupdesc->natts, tupdesc->tdhasoid);
108 
109  for (i = 0; i < desc->natts; i++)
110  {
111  Form_pg_attribute att = TupleDescAttr(desc, i);
112 
113  memcpy(att, &tupdesc->attrs[i], ATTRIBUTE_FIXED_PART_SIZE);
114  att->attnotnull = false;
115  att->atthasdef = false;
116  att->attidentity = '\0';
117  }
118 
119  desc->tdtypeid = tupdesc->tdtypeid;
120  desc->tdtypmod = tupdesc->tdtypmod;
121 
122  return desc;
123 }
Oid tdtypeid
Definition: tupdesc.h:74
bool tdhasoid
Definition: tupdesc.h:76
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
int natts
Definition: tupdesc.h:73
int32 tdtypmod
Definition: tupdesc.h:75
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
FormData_pg_attribute attrs[FLEXIBLE_ARRAY_MEMBER]
Definition: tupdesc.h:80
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
int i
TupleDesc CreateTupleDescCopyConstr ( TupleDesc  tupdesc)

Definition at line 131 of file tupdesc.c.

References attrDefault::adbin, ATTRIBUTE_FIXED_PART_SIZE, constrCheck::ccbin, constrCheck::ccname, constrCheck::ccnoinherit, constrCheck::ccvalid, tupleConstr::check, tupleDesc::constr, CreateTemplateTupleDesc(), tupleConstr::defval, tupleConstr::has_not_null, i, tupleDesc::natts, tupleConstr::num_check, tupleConstr::num_defval, palloc(), palloc0(), pstrdup(), tupleDesc::tdhasoid, tupleDesc::tdtypeid, tupleDesc::tdtypmod, and TupleDescAttr.

Referenced by CatalogCacheInitializeCache(), lookup_rowtype_tupdesc_copy(), and tuple_data_split_internal().

132 {
133  TupleDesc desc;
134  TupleConstr *constr = tupdesc->constr;
135  int i;
136 
137  desc = CreateTemplateTupleDesc(tupdesc->natts, tupdesc->tdhasoid);
138 
139  for (i = 0; i < desc->natts; i++)
140  {
141  memcpy(TupleDescAttr(desc, i),
142  TupleDescAttr(tupdesc, i),
144  }
145 
146  if (constr)
147  {
148  TupleConstr *cpy = (TupleConstr *) palloc0(sizeof(TupleConstr));
149 
150  cpy->has_not_null = constr->has_not_null;
151 
152  if ((cpy->num_defval = constr->num_defval) > 0)
153  {
154  cpy->defval = (AttrDefault *) palloc(cpy->num_defval * sizeof(AttrDefault));
155  memcpy(cpy->defval, constr->defval, cpy->num_defval * sizeof(AttrDefault));
156  for (i = cpy->num_defval - 1; i >= 0; i--)
157  {
158  if (constr->defval[i].adbin)
159  cpy->defval[i].adbin = pstrdup(constr->defval[i].adbin);
160  }
161  }
162 
163  if ((cpy->num_check = constr->num_check) > 0)
164  {
165  cpy->check = (ConstrCheck *) palloc(cpy->num_check * sizeof(ConstrCheck));
166  memcpy(cpy->check, constr->check, cpy->num_check * sizeof(ConstrCheck));
167  for (i = cpy->num_check - 1; i >= 0; i--)
168  {
169  if (constr->check[i].ccname)
170  cpy->check[i].ccname = pstrdup(constr->check[i].ccname);
171  if (constr->check[i].ccbin)
172  cpy->check[i].ccbin = pstrdup(constr->check[i].ccbin);
173  cpy->check[i].ccvalid = constr->check[i].ccvalid;
174  cpy->check[i].ccnoinherit = constr->check[i].ccnoinherit;
175  }
176  }
177 
178  desc->constr = cpy;
179  }
180 
181  desc->tdtypeid = tupdesc->tdtypeid;
182  desc->tdtypmod = tupdesc->tdtypmod;
183 
184  return desc;
185 }
Oid tdtypeid
Definition: tupdesc.h:74
char * ccname
Definition: tupdesc.h:30
bool tdhasoid
Definition: tupdesc.h:76
bool ccnoinherit
Definition: tupdesc.h:33
ConstrCheck * check
Definition: tupdesc.h:40
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
char * pstrdup(const char *in)
Definition: mcxt.c:1076
char * ccbin
Definition: tupdesc.h:31
int natts
Definition: tupdesc.h:73
int32 tdtypmod
Definition: tupdesc.h:75
AttrDefault * defval
Definition: tupdesc.h:39
char * adbin
Definition: tupdesc.h:25
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
bool has_not_null
Definition: tupdesc.h:43
void * palloc0(Size size)
Definition: mcxt.c:877
uint16 num_defval
Definition: tupdesc.h:41
TupleConstr * constr
Definition: tupdesc.h:78
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:43
void * palloc(Size size)
Definition: mcxt.c:848
bool ccvalid
Definition: tupdesc.h:32
int i
uint16 num_check
Definition: tupdesc.h:42
void DecrTupleDescRefCount ( TupleDesc  tupdesc)

Definition at line 319 of file tupdesc.c.

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

Referenced by ATExecAddOf(), cache_record_field_properties(), ExecInitExprRec(), ResourceOwnerReleaseInternal(), and transformOfType().

320 {
321  Assert(tupdesc->tdrefcount > 0);
322 
324  if (--tupdesc->tdrefcount == 0)
325  FreeTupleDesc(tupdesc);
326 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:138
void ResourceOwnerForgetTupleDesc(ResourceOwner owner, TupleDesc tupdesc)
Definition: resowner.c:1103
#define Assert(condition)
Definition: c.h:681
void FreeTupleDesc(TupleDesc tupdesc)
Definition: tupdesc.c:251
int tdrefcount
Definition: tupdesc.h:77
bool equalTupleDescs ( TupleDesc  tupdesc1,
TupleDesc  tupdesc2 
)

Definition at line 337 of file tupdesc.c.

References attrDefault::adbin, attrDefault::adnum, constrCheck::ccbin, constrCheck::ccname, constrCheck::ccnoinherit, constrCheck::ccvalid, tupleConstr::check, tupleDesc::constr, tupleConstr::defval, tupleConstr::has_not_null, i, NameStr, tupleDesc::natts, tupleConstr::num_check, tupleConstr::num_defval, tupleDesc::tdhasoid, tupleDesc::tdtypeid, and TupleDescAttr.

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

338 {
339  int i,
340  j,
341  n;
342 
343  if (tupdesc1->natts != tupdesc2->natts)
344  return false;
345  if (tupdesc1->tdtypeid != tupdesc2->tdtypeid)
346  return false;
347  if (tupdesc1->tdhasoid != tupdesc2->tdhasoid)
348  return false;
349 
350  for (i = 0; i < tupdesc1->natts; i++)
351  {
352  Form_pg_attribute attr1 = TupleDescAttr(tupdesc1, i);
353  Form_pg_attribute attr2 = TupleDescAttr(tupdesc2, i);
354 
355  /*
356  * We do not need to check every single field here: we can disregard
357  * attrelid and attnum (which were used to place the row in the attrs
358  * array in the first place). It might look like we could dispense
359  * with checking attlen/attbyval/attalign, since these are derived
360  * from atttypid; but in the case of dropped columns we must check
361  * them (since atttypid will be zero for all dropped columns) and in
362  * general it seems safer to check them always.
363  *
364  * attcacheoff must NOT be checked since it's possibly not set in both
365  * copies.
366  */
367  if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
368  return false;
369  if (attr1->atttypid != attr2->atttypid)
370  return false;
371  if (attr1->attstattarget != attr2->attstattarget)
372  return false;
373  if (attr1->attlen != attr2->attlen)
374  return false;
375  if (attr1->attndims != attr2->attndims)
376  return false;
377  if (attr1->atttypmod != attr2->atttypmod)
378  return false;
379  if (attr1->attbyval != attr2->attbyval)
380  return false;
381  if (attr1->attstorage != attr2->attstorage)
382  return false;
383  if (attr1->attalign != attr2->attalign)
384  return false;
385  if (attr1->attnotnull != attr2->attnotnull)
386  return false;
387  if (attr1->atthasdef != attr2->atthasdef)
388  return false;
389  if (attr1->attidentity != attr2->attidentity)
390  return false;
391  if (attr1->attisdropped != attr2->attisdropped)
392  return false;
393  if (attr1->attislocal != attr2->attislocal)
394  return false;
395  if (attr1->attinhcount != attr2->attinhcount)
396  return false;
397  if (attr1->attcollation != attr2->attcollation)
398  return false;
399  /* attacl, attoptions and attfdwoptions are not even present... */
400  }
401 
402  if (tupdesc1->constr != NULL)
403  {
404  TupleConstr *constr1 = tupdesc1->constr;
405  TupleConstr *constr2 = tupdesc2->constr;
406 
407  if (constr2 == NULL)
408  return false;
409  if (constr1->has_not_null != constr2->has_not_null)
410  return false;
411  n = constr1->num_defval;
412  if (n != (int) constr2->num_defval)
413  return false;
414  for (i = 0; i < n; i++)
415  {
416  AttrDefault *defval1 = constr1->defval + i;
417  AttrDefault *defval2 = constr2->defval;
418 
419  /*
420  * We can't assume that the items are always read from the system
421  * catalogs in the same order; so use the adnum field to identify
422  * the matching item to compare.
423  */
424  for (j = 0; j < n; defval2++, j++)
425  {
426  if (defval1->adnum == defval2->adnum)
427  break;
428  }
429  if (j >= n)
430  return false;
431  if (strcmp(defval1->adbin, defval2->adbin) != 0)
432  return false;
433  }
434  n = constr1->num_check;
435  if (n != (int) constr2->num_check)
436  return false;
437  for (i = 0; i < n; i++)
438  {
439  ConstrCheck *check1 = constr1->check + i;
440  ConstrCheck *check2 = constr2->check;
441 
442  /*
443  * Similarly, don't assume that the checks are always read in the
444  * same order; match them up by name and contents. (The name
445  * *should* be unique, but...)
446  */
447  for (j = 0; j < n; check2++, j++)
448  {
449  if (strcmp(check1->ccname, check2->ccname) == 0 &&
450  strcmp(check1->ccbin, check2->ccbin) == 0 &&
451  check1->ccvalid == check2->ccvalid &&
452  check1->ccnoinherit == check2->ccnoinherit)
453  break;
454  }
455  if (j >= n)
456  return false;
457  }
458  }
459  else if (tupdesc2->constr != NULL)
460  return false;
461  return true;
462 }
Oid tdtypeid
Definition: tupdesc.h:74
char * ccname
Definition: tupdesc.h:30
bool tdhasoid
Definition: tupdesc.h:76
bool ccnoinherit
Definition: tupdesc.h:33
ConstrCheck * check
Definition: tupdesc.h:40
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
char * ccbin
Definition: tupdesc.h:31
int natts
Definition: tupdesc.h:73
AttrDefault * defval
Definition: tupdesc.h:39
AttrNumber adnum
Definition: tupdesc.h:24
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
char * adbin
Definition: tupdesc.h:25
bool has_not_null
Definition: tupdesc.h:43
uint16 num_defval
Definition: tupdesc.h:41
TupleConstr * constr
Definition: tupdesc.h:78
bool ccvalid
Definition: tupdesc.h:32
int i
#define NameStr(name)
Definition: c.h:493
uint16 num_check
Definition: tupdesc.h:42
void FreeTupleDesc ( TupleDesc  tupdesc)

Definition at line 251 of file tupdesc.c.

References Assert, tupleConstr::check, tupleDesc::constr, tupleConstr::defval, i, tupleConstr::num_check, tupleConstr::num_defval, pfree(), and tupleDesc::tdrefcount.

Referenced by AtEOXact_RelationCache(), DecrTupleDescRefCount(), exec_move_row(), exec_stmt_block(), ExecMakeTableFunctionResult(), ExecPrepareTuplestoreResult(), ordered_set_startup(), PLy_result_dealloc(), populate_composite(), RelationDestroyRelation(), RevalidateCachedQuery(), TypeCacheRelCallback(), and walrcv_clear_result().

252 {
253  int i;
254 
255  /*
256  * Possibly this should assert tdrefcount == 0, to disallow explicit
257  * freeing of un-refcounted tupdescs?
258  */
259  Assert(tupdesc->tdrefcount <= 0);
260 
261  if (tupdesc->constr)
262  {
263  if (tupdesc->constr->num_defval > 0)
264  {
265  AttrDefault *attrdef = tupdesc->constr->defval;
266 
267  for (i = tupdesc->constr->num_defval - 1; i >= 0; i--)
268  {
269  if (attrdef[i].adbin)
270  pfree(attrdef[i].adbin);
271  }
272  pfree(attrdef);
273  }
274  if (tupdesc->constr->num_check > 0)
275  {
276  ConstrCheck *check = tupdesc->constr->check;
277 
278  for (i = tupdesc->constr->num_check - 1; i >= 0; i--)
279  {
280  if (check[i].ccname)
281  pfree(check[i].ccname);
282  if (check[i].ccbin)
283  pfree(check[i].ccbin);
284  }
285  pfree(check);
286  }
287  pfree(tupdesc->constr);
288  }
289 
290  pfree(tupdesc);
291 }
ConstrCheck * check
Definition: tupdesc.h:40
void pfree(void *pointer)
Definition: mcxt.c:949
AttrDefault * defval
Definition: tupdesc.h:39
uint16 num_defval
Definition: tupdesc.h:41
#define Assert(condition)
Definition: c.h:681
TupleConstr * constr
Definition: tupdesc.h:78
int tdrefcount
Definition: tupdesc.h:77
int i
uint16 num_check
Definition: tupdesc.h:42
uint32 hashTupleDesc ( TupleDesc  tupdesc)

Definition at line 475 of file tupdesc.c.

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

Referenced by record_type_typmod_hash(), and shared_record_table_hash().

476 {
477  uint32 s;
478  int i;
479 
480  s = hash_combine(0, hash_uint32(desc->natts));
481  s = hash_combine(s, hash_uint32(desc->tdtypeid));
482  s = hash_combine(s, hash_uint32(desc->tdhasoid));
483  for (i = 0; i < desc->natts; ++i)
484  s = hash_combine(s, hash_uint32(TupleDescAttr(desc, i)->atttypid));
485 
486  return s;
487 }
static uint32 hash_combine(uint32 a, uint32 b)
Definition: hashutils.h:17
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
unsigned int uint32
Definition: c.h:258
Datum hash_uint32(uint32 k)
Definition: hashfunc.c:853
int i
void IncrTupleDescRefCount ( TupleDesc  tupdesc)

Definition at line 301 of file tupdesc.c.

References Assert, CurrentResourceOwner, ResourceOwnerEnlargeTupleDescs(), ResourceOwnerRememberTupleDesc(), and tupleDesc::tdrefcount.

Referenced by cache_record_field_properties().

302 {
303  Assert(tupdesc->tdrefcount >= 0);
304 
306  tupdesc->tdrefcount++;
308 }
ResourceOwner CurrentResourceOwner
Definition: resowner.c:138
void ResourceOwnerRememberTupleDesc(ResourceOwner owner, TupleDesc tupdesc)
Definition: resowner.c:1094
void ResourceOwnerEnlargeTupleDescs(ResourceOwner owner)
Definition: resowner.c:1083
#define Assert(condition)
Definition: c.h:681
int tdrefcount
Definition: tupdesc.h:77
void TupleDescCopy ( TupleDesc  dst,
TupleDesc  src 
)

Definition at line 196 of file tupdesc.c.

References tupleDesc::constr, tupleDesc::tdrefcount, and TupleDescSize.

Referenced by share_tupledesc().

197 {
198  memcpy(dst, src, TupleDescSize(src));
199  dst->constr = NULL;
200  dst->tdrefcount = -1;
201 }
#define TupleDescSize(src)
Definition: tupdesc.h:95
TupleConstr * constr
Definition: tupdesc.h:78
int tdrefcount
Definition: tupdesc.h:77
void TupleDescCopyEntry ( TupleDesc  dst,
AttrNumber  dstAttno,
TupleDesc  src,
AttrNumber  srcAttno 
)

Definition at line 211 of file tupdesc.c.

References AssertArg, ATTRIBUTE_FIXED_PART_SIZE, PointerIsValid, and TupleDescAttr.

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

213 {
214  Form_pg_attribute dstAtt = TupleDescAttr(dst, dstAttno - 1);
215  Form_pg_attribute srcAtt = TupleDescAttr(src, srcAttno - 1);
216 
217  /*
218  * sanity checks
219  */
222  AssertArg(srcAttno >= 1);
223  AssertArg(srcAttno <= src->natts);
224  AssertArg(dstAttno >= 1);
225  AssertArg(dstAttno <= dst->natts);
226 
227  memcpy(dstAtt, srcAtt, ATTRIBUTE_FIXED_PART_SIZE);
228 
229  /*
230  * Aside from updating the attno, we'd better reset attcacheoff.
231  *
232  * XXX Actually, to be entirely safe we'd need to reset the attcacheoff of
233  * all following columns in dst as well. Current usage scenarios don't
234  * require that though, because all following columns will get initialized
235  * by other uses of this function or TupleDescInitEntry. So we cheat a
236  * bit to avoid a useless O(N^2) penalty.
237  */
238  dstAtt->attnum = dstAttno;
239  dstAtt->attcacheoff = -1;
240 
241  /* since we're not copying constraints or defaults, clear these */
242  dstAtt->attnotnull = false;
243  dstAtt->atthasdef = false;
244  dstAtt->attidentity = '\0';
245 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define ATTRIBUTE_FIXED_PART_SIZE
Definition: pg_attribute.h:179
#define AssertArg(condition)
Definition: c.h:683
#define PointerIsValid(pointer)
Definition: c.h:520
void TupleDescInitBuiltinEntry ( TupleDesc  desc,
AttrNumber  attributeNumber,
const char *  attributeName,
Oid  oidtypeid,
int32  typmod,
int  attdim 
)

Definition at line 576 of file tupdesc.c.

References Assert, AssertArg, BOOLOID, DEFAULT_COLLATION_OID, INT4OID, INT8OID, InvalidOid, namestrcpy(), PointerIsValid, TEXTARRAYOID, TEXTOID, and TupleDescAttr.

Referenced by CreateReplicationSlot(), IdentifySystem(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

582 {
583  Form_pg_attribute att;
584 
585  /* sanity checks */
586  AssertArg(PointerIsValid(desc));
587  AssertArg(attributeNumber >= 1);
588  AssertArg(attributeNumber <= desc->natts);
589 
590  /* initialize the attribute fields */
591  att = TupleDescAttr(desc, attributeNumber - 1);
592  att->attrelid = 0; /* dummy value */
593 
594  /* unlike TupleDescInitEntry, we require an attribute name */
595  Assert(attributeName != NULL);
596  namestrcpy(&(att->attname), attributeName);
597 
598  att->attstattarget = -1;
599  att->attcacheoff = -1;
600  att->atttypmod = typmod;
601 
602  att->attnum = attributeNumber;
603  att->attndims = attdim;
604 
605  att->attnotnull = false;
606  att->atthasdef = false;
607  att->attidentity = '\0';
608  att->attisdropped = false;
609  att->attislocal = true;
610  att->attinhcount = 0;
611  /* attacl, attoptions and attfdwoptions are not present in tupledescs */
612 
613  att->atttypid = oidtypeid;
614 
615  /*
616  * Our goal here is to support just enough types to let basic builtin
617  * commands work without catalog access - e.g. so that we can do certain
618  * things even in processes that are not connected to a database.
619  */
620  switch (oidtypeid)
621  {
622  case TEXTOID:
623  case TEXTARRAYOID:
624  att->attlen = -1;
625  att->attbyval = false;
626  att->attalign = 'i';
627  att->attstorage = 'x';
628  att->attcollation = DEFAULT_COLLATION_OID;
629  break;
630 
631  case BOOLOID:
632  att->attlen = 1;
633  att->attbyval = true;
634  att->attalign = 'c';
635  att->attstorage = 'p';
636  att->attcollation = InvalidOid;
637  break;
638 
639  case INT4OID:
640  att->attlen = 4;
641  att->attbyval = true;
642  att->attalign = 'i';
643  att->attstorage = 'p';
644  att->attcollation = InvalidOid;
645  break;
646 
647  case INT8OID:
648  att->attlen = 8;
649  att->attbyval = FLOAT8PASSBYVAL;
650  att->attalign = 'd';
651  att->attstorage = 'p';
652  att->attcollation = InvalidOid;
653  break;
654  }
655 }
#define TEXTOID
Definition: pg_type.h:324
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
#define INT4OID
Definition: pg_type.h:316
int namestrcpy(Name name, const char *str)
Definition: name.c:216
#define TEXTARRAYOID
Definition: pg_type.h:470
#define DEFAULT_COLLATION_OID
Definition: pg_collation.h:75
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define AssertArg(condition)
Definition: c.h:683
#define InvalidOid
Definition: postgres_ext.h:36
#define INT8OID
Definition: pg_type.h:304
#define Assert(condition)
Definition: c.h:681
#define BOOLOID
Definition: pg_type.h:288
#define PointerIsValid(pointer)
Definition: c.h:520
void TupleDescInitEntry ( TupleDesc  desc,
AttrNumber  attributeNumber,
const char *  attributeName,
Oid  oidtypeid,
int32  typmod,
int  attdim 
)

Definition at line 505 of file tupdesc.c.

References AssertArg, elog, ERROR, GETSTRUCT, HeapTupleIsValid, MemSet, NAMEDATALEN, NameStr, namestrcpy(), ObjectIdGetDatum, PointerIsValid, ReleaseSysCache(), SearchSysCache1(), TupleDescAttr, and TYPEOID.

Referenced by aclexplode(), addRangeTableEntryForFunction(), brtuple_disk_tupdesc(), build_function_result_tupdesc_d(), build_row_from_vars(), BuildDescForRelation(), BuildDescFromLists(), create_toast_table(), dblink_get_notify(), dblink_get_pkey(), ExecInitFunctionScan(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), ExplainResultDesc(), GetPGVariableResultDesc(), gistrescan(), init_sexpr(), initGinState(), libpqrcv_processTuples(), materializeQueryResult(), materializeResult(), ordered_set_startup(), pg_buffercache_pages(), pg_control_checkpoint(), pg_control_init(), pg_control_recovery(), pg_control_system(), pg_cursor(), pg_get_keywords(), pg_get_multixact_members(), pg_get_object_address(), pg_identify_object(), pg_identify_object_as_address(), pg_last_committed_xact(), pg_lock_status(), pg_logdir_ls(), pg_ls_dir_files(), pg_prepared_statement(), pg_prepared_xact(), pg_sequence_parameters(), pg_stat_file(), pg_stat_get_archiver(), pg_timezone_abbrevs(), pg_timezone_names(), pg_visibility_map_summary(), pg_visibility_tupdesc(), pg_walfile_name_offset(), prs_setup_firstcall(), resolve_polymorphic_tupdesc(), show_all_file_settings(), show_all_settings(), ts_setup_firstcall(), tsvector_unnest(), tt_setup_firstcall(), and TypeGetTupleDesc().

511 {
512  HeapTuple tuple;
513  Form_pg_type typeForm;
514  Form_pg_attribute att;
515 
516  /*
517  * sanity checks
518  */
519  AssertArg(PointerIsValid(desc));
520  AssertArg(attributeNumber >= 1);
521  AssertArg(attributeNumber <= desc->natts);
522 
523  /*
524  * initialize the attribute fields
525  */
526  att = TupleDescAttr(desc, attributeNumber - 1);
527 
528  att->attrelid = 0; /* dummy value */
529 
530  /*
531  * Note: attributeName can be NULL, because the planner doesn't always
532  * fill in valid resname values in targetlists, particularly for resjunk
533  * attributes. Also, do nothing if caller wants to re-use the old attname.
534  */
535  if (attributeName == NULL)
536  MemSet(NameStr(att->attname), 0, NAMEDATALEN);
537  else if (attributeName != NameStr(att->attname))
538  namestrcpy(&(att->attname), attributeName);
539 
540  att->attstattarget = -1;
541  att->attcacheoff = -1;
542  att->atttypmod = typmod;
543 
544  att->attnum = attributeNumber;
545  att->attndims = attdim;
546 
547  att->attnotnull = false;
548  att->atthasdef = false;
549  att->attidentity = '\0';
550  att->attisdropped = false;
551  att->attislocal = true;
552  att->attinhcount = 0;
553  /* attacl, attoptions and attfdwoptions are not present in tupledescs */
554 
555  tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(oidtypeid));
556  if (!HeapTupleIsValid(tuple))
557  elog(ERROR, "cache lookup failed for type %u", oidtypeid);
558  typeForm = (Form_pg_type) GETSTRUCT(tuple);
559 
560  att->atttypid = oidtypeid;
561  att->attlen = typeForm->typlen;
562  att->attbyval = typeForm->typbyval;
563  att->attalign = typeForm->typalign;
564  att->attstorage = typeForm->typstorage;
565  att->attcollation = typeForm->typcollation;
566 
567  ReleaseSysCache(tuple);
568 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
#define MemSet(start, val, len)
Definition: c.h:863
FormData_pg_type * Form_pg_type
Definition: pg_type.h:233
int namestrcpy(Name name, const char *str)
Definition: name.c:216
#define NAMEDATALEN
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
#define AssertArg(condition)
Definition: c.h:683
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NameStr(name)
Definition: c.h:493
#define elog
Definition: elog.h:219
#define PointerIsValid(pointer)
Definition: c.h:520
void TupleDescInitEntryCollation ( TupleDesc  desc,
AttrNumber  attributeNumber,
Oid  collationid 
)

Definition at line 664 of file tupdesc.c.

References AssertArg, PointerIsValid, and TupleDescAttr.

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

667 {
668  /*
669  * sanity checks
670  */
671  AssertArg(PointerIsValid(desc));
672  AssertArg(attributeNumber >= 1);
673  AssertArg(attributeNumber <= desc->natts);
674 
675  TupleDescAttr(desc, attributeNumber - 1)->attcollation = collationid;
676 }
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:84
#define AssertArg(condition)
Definition: c.h:683
#define PointerIsValid(pointer)
Definition: c.h:520