1 /*------------------------------------------------------------------------- 2 * 3 * heap.h 4 * prototypes for functions in backend/catalog/heap.c 5 * 6 * 7 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group 8 * Portions Copyright (c) 1994, Regents of the University of California 9 * 10 * src/include/catalog/heap.h 11 * 12 *------------------------------------------------------------------------- 13 */ 14 #ifndef HEAP_H 15 #define HEAP_H 16 17 #include "catalog/indexing.h" 18 #include "catalog/objectaddress.h" 19 #include "parser/parse_node.h" 20 21 22 typedef struct RawColumnDefault 23 { 24 AttrNumber attnum; /* attribute to attach default to */ 25 Node *raw_default; /* default value (untransformed parse tree) */ 26 } RawColumnDefault; 27 28 typedef struct CookedConstraint 29 { 30 ConstrType contype; /* CONSTR_DEFAULT or CONSTR_CHECK */ 31 Oid conoid; /* constr OID if created, otherwise Invalid */ 32 char *name; /* name, or NULL if none */ 33 AttrNumber attnum; /* which attr (only for DEFAULT) */ 34 Node *expr; /* transformed default or check expr */ 35 bool skip_validation; /* skip validation? (only for CHECK) */ 36 bool is_local; /* constraint has local (non-inherited) def */ 37 int inhcount; /* number of times constraint is inherited */ 38 bool is_no_inherit; /* constraint has local def and cannot be 39 * inherited */ 40 } CookedConstraint; 41 42 extern Relation heap_create(const char *relname, 43 Oid relnamespace, 44 Oid reltablespace, 45 Oid relid, 46 Oid relfilenode, 47 TupleDesc tupDesc, 48 char relkind, 49 char relpersistence, 50 bool shared_relation, 51 bool mapped_relation, 52 bool allow_system_table_mods); 53 54 extern Oid heap_create_with_catalog(const char *relname, 55 Oid relnamespace, 56 Oid reltablespace, 57 Oid relid, 58 Oid reltypeid, 59 Oid reloftypeid, 60 Oid ownerid, 61 TupleDesc tupdesc, 62 List *cooked_constraints, 63 char relkind, 64 char relpersistence, 65 bool shared_relation, 66 bool mapped_relation, 67 bool oidislocal, 68 int oidinhcount, 69 OnCommitAction oncommit, 70 Datum reloptions, 71 bool use_user_acl, 72 bool allow_system_table_mods, 73 bool is_internal, 74 ObjectAddress *typaddress); 75 76 extern void heap_create_init_fork(Relation rel); 77 78 extern void heap_drop_with_catalog(Oid relid); 79 80 extern void heap_truncate(List *relids); 81 82 extern void heap_truncate_one_rel(Relation rel); 83 84 extern void heap_truncate_check_FKs(List *relations, bool tempTables); 85 86 extern List *heap_truncate_find_FKs(List *relationIds); 87 88 extern void InsertPgAttributeTuple(Relation pg_attribute_rel, 89 Form_pg_attribute new_attribute, 90 CatalogIndexState indstate); 91 92 extern void InsertPgClassTuple(Relation pg_class_desc, 93 Relation new_rel_desc, 94 Oid new_rel_oid, 95 Datum relacl, 96 Datum reloptions); 97 98 extern List *AddRelationNewConstraints(Relation rel, 99 List *newColDefaults, 100 List *newConstraints, 101 bool allow_merge, 102 bool is_local, 103 bool is_internal); 104 105 extern Oid StoreAttrDefault(Relation rel, AttrNumber attnum, 106 Node *expr, bool is_internal); 107 108 extern Node *cookDefault(ParseState *pstate, 109 Node *raw_default, 110 Oid atttypid, 111 int32 atttypmod, 112 char *attname); 113 114 extern void DeleteRelationTuple(Oid relid); 115 extern void DeleteAttributeTuples(Oid relid); 116 extern void DeleteSystemAttributeTuples(Oid relid); 117 extern void RemoveAttributeById(Oid relid, AttrNumber attnum); 118 extern void RemoveAttrDefault(Oid relid, AttrNumber attnum, 119 DropBehavior behavior, bool complain, bool internal); 120 extern void RemoveAttrDefaultById(Oid attrdefId); 121 extern void RemoveStatistics(Oid relid, AttrNumber attnum); 122 123 extern Form_pg_attribute SystemAttributeDefinition(AttrNumber attno, 124 bool relhasoids); 125 126 extern Form_pg_attribute SystemAttributeByName(const char *attname, 127 bool relhasoids); 128 129 extern void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind, 130 bool allow_system_table_mods); 131 132 extern void CheckAttributeType(const char *attname, 133 Oid atttypid, Oid attcollation, 134 List *containing_rowtypes, 135 bool allow_system_table_mods); 136 137 /* pg_partitioned_table catalog manipulation functions */ 138 extern void StorePartitionKey(Relation rel, 139 char strategy, 140 int16 partnatts, 141 AttrNumber *partattrs, 142 List *partexprs, 143 Oid *partopclass, 144 Oid *partcollation); 145 extern void RemovePartitionKeyByRelId(Oid relid); 146 extern void StorePartitionBound(Relation rel, Relation parent, 147 PartitionBoundSpec *bound); 148 149 #endif /* HEAP_H */ 150