1/*-------------------------------------------------------------------------
2 *
3 * heap.h
4 * prototypes for functions in backend/catalog/heap.c
5 *
6 *
7 * Portions Copyright (c) 1996-2019, 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/* flag bits for CheckAttributeType/CheckAttributeNamesTypes */
23#define CHKATYPE_ANYARRAY 0x01 /* allow ANYARRAY */
24#define CHKATYPE_ANYRECORD 0x02 /* allow RECORD and RECORD[] */
25
26typedef struct RawColumnDefault
27{
28 AttrNumber attnum; /* attribute to attach default to */
29 Node *raw_default; /* default value (untransformed parse tree) */
30 bool missingMode; /* true if part of add column processing */
31 char generated; /* attgenerated setting */
32} RawColumnDefault;
33
34typedef struct CookedConstraint
35{
36 ConstrType contype; /* CONSTR_DEFAULT or CONSTR_CHECK */
37 Oid conoid; /* constr OID if created, otherwise Invalid */
38 char *name; /* name, or NULL if none */
39 AttrNumber attnum; /* which attr (only for DEFAULT) */
40 Node *expr; /* transformed default or check expr */
41 bool skip_validation; /* skip validation? (only for CHECK) */
42 bool is_local; /* constraint has local (non-inherited) def */
43 int inhcount; /* number of times constraint is inherited */
44 bool is_no_inherit; /* constraint has local def and cannot be
45 * inherited */
46} CookedConstraint;
47
48extern Relation heap_create(const char *relname,
49 Oid relnamespace,
50 Oid reltablespace,
51 Oid relid,
52 Oid relfilenode,
53 Oid accessmtd,
54 TupleDesc tupDesc,
55 char relkind,
56 char relpersistence,
57 bool shared_relation,
58 bool mapped_relation,
59 bool allow_system_table_mods,
60 TransactionId *relfrozenxid,
61 MultiXactId *relminmxid);
62
63extern Oid heap_create_with_catalog(const char *relname,
64 Oid relnamespace,
65 Oid reltablespace,
66 Oid relid,
67 Oid reltypeid,
68 Oid reloftypeid,
69 Oid ownerid,
70 Oid accessmtd,
71 TupleDesc tupdesc,
72 List *cooked_constraints,
73 char relkind,
74 char relpersistence,
75 bool shared_relation,
76 bool mapped_relation,
77 OnCommitAction oncommit,
78 Datum reloptions,
79 bool use_user_acl,
80 bool allow_system_table_mods,
81 bool is_internal,
82 Oid relrewrite,
83 ObjectAddress *typaddress);
84
85extern void heap_drop_with_catalog(Oid relid);
86
87extern void heap_truncate(List *relids);
88
89extern void heap_truncate_one_rel(Relation rel);
90
91extern void heap_truncate_check_FKs(List *relations, bool tempTables);
92
93extern List *heap_truncate_find_FKs(List *relationIds);
94
95extern void InsertPgAttributeTuple(Relation pg_attribute_rel,
96 Form_pg_attribute new_attribute,
97 CatalogIndexState indstate);
98
99extern void InsertPgClassTuple(Relation pg_class_desc,
100 Relation new_rel_desc,
101 Oid new_rel_oid,
102 Datum relacl,
103 Datum reloptions);
104
105extern List *AddRelationNewConstraints(Relation rel,
106 List *newColDefaults,
107 List *newConstraints,
108 bool allow_merge,
109 bool is_local,
110 bool is_internal,
111 const char *queryString);
112
113extern void RelationClearMissing(Relation rel);
114extern void SetAttrMissing(Oid relid, char *attname, char *value);
115
116extern Oid StoreAttrDefault(Relation rel, AttrNumber attnum,
117 Node *expr, bool is_internal,
118 bool add_column_mode);
119
120extern Node *cookDefault(ParseState *pstate,
121 Node *raw_default,
122 Oid atttypid,
123 int32 atttypmod,
124 const char *attname,
125 char attgenerated);
126
127extern void DeleteRelationTuple(Oid relid);
128extern void DeleteAttributeTuples(Oid relid);
129extern void DeleteSystemAttributeTuples(Oid relid);
130extern void RemoveAttributeById(Oid relid, AttrNumber attnum);
131extern void RemoveAttrDefault(Oid relid, AttrNumber attnum,
132 DropBehavior behavior, bool complain, bool internal);
133extern void RemoveAttrDefaultById(Oid attrdefId);
134extern void RemoveStatistics(Oid relid, AttrNumber attnum);
135
136extern const FormData_pg_attribute *SystemAttributeDefinition(AttrNumber attno);
137
138extern const FormData_pg_attribute *SystemAttributeByName(const char *attname);
139
140extern void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind,
141 int flags);
142
143extern void CheckAttributeType(const char *attname,
144 Oid atttypid, Oid attcollation,
145 List *containing_rowtypes,
146 int flags);
147
148/* pg_partitioned_table catalog manipulation functions */
149extern void StorePartitionKey(Relation rel,
150 char strategy,
151 int16 partnatts,
152 AttrNumber *partattrs,
153 List *partexprs,
154 Oid *partopclass,
155 Oid *partcollation);
156extern void RemovePartitionKeyByRelId(Oid relid);
157extern void StorePartitionBound(Relation rel, Relation parent,
158 PartitionBoundSpec *bound);
159
160#endif /* HEAP_H */
161