1 /*-------------------------------------------------------------------------
2  *
3  * index.h
4  *	  prototypes for catalog/index.c.
5  *
6  *
7  * Portions Copyright (c) 1996-2016, 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 extern Oid index_create(Relation heapRelation,
47 			 const char *indexRelationName,
48 			 Oid indexRelationId,
49 			 Oid relFileNode,
50 			 IndexInfo *indexInfo,
51 			 List *indexColNames,
52 			 Oid accessMethodObjectId,
53 			 Oid tableSpaceId,
54 			 Oid *collationObjectId,
55 			 Oid *classObjectId,
56 			 int16 *coloptions,
57 			 Datum reloptions,
58 			 bool isprimary,
59 			 bool isconstraint,
60 			 bool deferrable,
61 			 bool initdeferred,
62 			 bool allow_system_table_mods,
63 			 bool skip_build,
64 			 bool concurrent,
65 			 bool is_internal,
66 			 bool if_not_exists);
67 
68 extern ObjectAddress index_constraint_create(Relation heapRelation,
69 						Oid indexRelationId,
70 						IndexInfo *indexInfo,
71 						const char *constraintName,
72 						char constraintType,
73 						bool deferrable,
74 						bool initdeferred,
75 						bool mark_as_primary,
76 						bool update_pgindex,
77 						bool remove_old_dependencies,
78 						bool allow_system_table_mods,
79 						bool is_internal);
80 
81 extern void index_drop(Oid indexId, bool concurrent);
82 
83 extern IndexInfo *BuildIndexInfo(Relation index);
84 
85 extern IndexInfo *BuildDummyIndexInfo(Relation index);
86 
87 extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii);
88 
89 extern void FormIndexDatum(IndexInfo *indexInfo,
90 			   TupleTableSlot *slot,
91 			   EState *estate,
92 			   Datum *values,
93 			   bool *isnull);
94 
95 extern void index_build(Relation heapRelation,
96 			Relation indexRelation,
97 			IndexInfo *indexInfo,
98 			bool isprimary,
99 			bool isreindex);
100 
101 extern double IndexBuildHeapScan(Relation heapRelation,
102 				   Relation indexRelation,
103 				   IndexInfo *indexInfo,
104 				   bool allow_sync,
105 				   IndexBuildCallback callback,
106 				   void *callback_state);
107 extern double IndexBuildHeapRangeScan(Relation heapRelation,
108 						Relation indexRelation,
109 						IndexInfo *indexInfo,
110 						bool allow_sync,
111 						bool anyvisible,
112 						BlockNumber start_blockno,
113 						BlockNumber end_blockno,
114 						IndexBuildCallback callback,
115 						void *callback_state);
116 
117 extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
118 
119 extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action);
120 
121 extern Oid	IndexGetRelation(Oid indexId, bool missing_ok);
122 
123 extern void reindex_index(Oid indexId, bool skip_constraint_checks,
124 			  char relpersistence, int options);
125 
126 /* Flag bits for reindex_relation(): */
127 #define REINDEX_REL_PROCESS_TOAST			0x01
128 #define REINDEX_REL_SUPPRESS_INDEX_USE		0x02
129 #define REINDEX_REL_CHECK_CONSTRAINTS		0x04
130 #define REINDEX_REL_FORCE_INDEXES_UNLOGGED	0x08
131 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
132 
133 extern bool reindex_relation(Oid relid, int flags, int options);
134 
135 extern bool ReindexIsProcessingHeap(Oid heapOid);
136 extern bool ReindexIsProcessingIndex(Oid indexOid);
137 
138 extern void ResetReindexState(int nestLevel);
139 
140 #endif   /* INDEX_H */
141