1 /*-------------------------------------------------------------------------
2  *
3  * index.h
4  *	  prototypes for catalog/index.c.
5  *
6  *
7  * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/catalog/index.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef INDEX_H
15 #define INDEX_H
16 
17 #include "catalog/objectaddress.h"
18 #include "nodes/execnodes.h"
19 
20 
21 #define DEFAULT_INDEX_TYPE	"btree"
22 
23 /* Typedef for callback function for IndexBuildHeapScan */
24 typedef void (*IndexBuildCallback) (Relation index,
25 									HeapTuple htup,
26 									Datum *values,
27 									bool *isnull,
28 									bool tupleIsAlive,
29 									void *state);
30 
31 /* Action code for index_set_state_flags */
32 typedef enum
33 {
34 	INDEX_CREATE_SET_READY,
35 	INDEX_CREATE_SET_VALID,
36 	INDEX_DROP_CLEAR_VALID,
37 	INDEX_DROP_SET_DEAD
38 } IndexStateFlagsAction;
39 
40 
41 extern void index_check_primary_key(Relation heapRel,
42 						IndexInfo *indexInfo,
43 						bool is_alter_table,
44 						IndexStmt *stmt);
45 
46 #define	INDEX_CREATE_IS_PRIMARY				(1 << 0)
47 #define	INDEX_CREATE_ADD_CONSTRAINT			(1 << 1)
48 #define	INDEX_CREATE_SKIP_BUILD				(1 << 2)
49 #define	INDEX_CREATE_CONCURRENT				(1 << 3)
50 #define	INDEX_CREATE_IF_NOT_EXISTS			(1 << 4)
51 #define	INDEX_CREATE_PARTITIONED			(1 << 5)
52 #define INDEX_CREATE_INVALID				(1 << 6)
53 
54 extern Oid index_create(Relation heapRelation,
55 			 const char *indexRelationName,
56 			 Oid indexRelationId,
57 			 Oid parentIndexRelid,
58 			 Oid parentConstraintId,
59 			 Oid relFileNode,
60 			 IndexInfo *indexInfo,
61 			 List *indexColNames,
62 			 Oid accessMethodObjectId,
63 			 Oid tableSpaceId,
64 			 Oid *collationObjectId,
65 			 Oid *classObjectId,
66 			 int16 *coloptions,
67 			 Datum reloptions,
68 			 bits16 flags,
69 			 bits16 constr_flags,
70 			 bool allow_system_table_mods,
71 			 bool is_internal,
72 			 Oid *constraintId);
73 
74 #define	INDEX_CONSTR_CREATE_MARK_AS_PRIMARY	(1 << 0)
75 #define	INDEX_CONSTR_CREATE_DEFERRABLE		(1 << 1)
76 #define	INDEX_CONSTR_CREATE_INIT_DEFERRED	(1 << 2)
77 #define	INDEX_CONSTR_CREATE_UPDATE_INDEX	(1 << 3)
78 #define	INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS	(1 << 4)
79 
80 extern ObjectAddress index_constraint_create(Relation heapRelation,
81 						Oid indexRelationId,
82 						Oid parentConstraintId,
83 						IndexInfo *indexInfo,
84 						const char *constraintName,
85 						char constraintType,
86 						bits16 constr_flags,
87 						bool allow_system_table_mods,
88 						bool is_internal);
89 
90 extern void index_drop(Oid indexId, bool concurrent);
91 
92 extern IndexInfo *BuildIndexInfo(Relation index);
93 
94 extern IndexInfo *BuildDummyIndexInfo(Relation index);
95 
96 extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
97 				 Oid *collations1, Oid *collations2,
98 				 Oid *opfamilies1, Oid *opfamilies2,
99 				 AttrNumber *attmap, int maplen);
100 
101 extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii);
102 
103 extern void FormIndexDatum(IndexInfo *indexInfo,
104 			   TupleTableSlot *slot,
105 			   EState *estate,
106 			   Datum *values,
107 			   bool *isnull);
108 
109 extern void index_build(Relation heapRelation,
110 			Relation indexRelation,
111 			IndexInfo *indexInfo,
112 			bool isprimary,
113 			bool isreindex,
114 			bool parallel);
115 
116 extern double IndexBuildHeapScan(Relation heapRelation,
117 				   Relation indexRelation,
118 				   IndexInfo *indexInfo,
119 				   bool allow_sync,
120 				   IndexBuildCallback callback,
121 				   void *callback_state,
122 				   HeapScanDesc scan);
123 extern double IndexBuildHeapRangeScan(Relation heapRelation,
124 						Relation indexRelation,
125 						IndexInfo *indexInfo,
126 						bool allow_sync,
127 						bool anyvisible,
128 						BlockNumber start_blockno,
129 						BlockNumber end_blockno,
130 						IndexBuildCallback callback,
131 						void *callback_state,
132 						HeapScanDesc scan);
133 
134 extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
135 
136 extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action);
137 
138 extern Oid	IndexGetRelation(Oid indexId, bool missing_ok);
139 
140 extern void reindex_index(Oid indexId, bool skip_constraint_checks,
141 			  char relpersistence, int options);
142 
143 /* Flag bits for reindex_relation(): */
144 #define REINDEX_REL_PROCESS_TOAST			0x01
145 #define REINDEX_REL_SUPPRESS_INDEX_USE		0x02
146 #define REINDEX_REL_CHECK_CONSTRAINTS		0x04
147 #define REINDEX_REL_FORCE_INDEXES_UNLOGGED	0x08
148 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
149 
150 extern bool reindex_relation(Oid relid, int flags, int options);
151 
152 extern bool ReindexIsProcessingHeap(Oid heapOid);
153 extern bool ReindexIsProcessingIndex(Oid indexOid);
154 
155 extern void ResetReindexState(int nestLevel);
156 extern Size EstimateReindexStateSpace(void);
157 extern void SerializeReindexState(Size maxsize, char *start_address);
158 extern void RestoreReindexState(void *reindexstate);
159 
160 extern void IndexSetParentIndex(Relation idx, Oid parentOid);
161 
162 #endif							/* INDEX_H */
163