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