1 | /*------------------------------------------------------------------------- |
2 | * |
3 | * index.h |
4 | * prototypes for catalog/index.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/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 | /* Action code for index_set_state_flags */ |
24 | typedef enum |
25 | { |
26 | INDEX_CREATE_SET_READY, |
27 | INDEX_CREATE_SET_VALID, |
28 | INDEX_DROP_CLEAR_VALID, |
29 | INDEX_DROP_SET_DEAD |
30 | } IndexStateFlagsAction; |
31 | |
32 | /* state info for validate_index bulkdelete callback */ |
33 | typedef struct ValidateIndexState |
34 | { |
35 | Tuplesortstate *tuplesort; /* for sorting the index TIDs */ |
36 | /* statistics (for debug purposes only): */ |
37 | double htups, |
38 | itups, |
39 | tups_inserted; |
40 | } ValidateIndexState; |
41 | |
42 | extern void index_check_primary_key(Relation heapRel, |
43 | IndexInfo *indexInfo, |
44 | bool is_alter_table, |
45 | IndexStmt *stmt); |
46 | |
47 | #define INDEX_CREATE_IS_PRIMARY (1 << 0) |
48 | #define INDEX_CREATE_ADD_CONSTRAINT (1 << 1) |
49 | #define INDEX_CREATE_SKIP_BUILD (1 << 2) |
50 | #define INDEX_CREATE_CONCURRENT (1 << 3) |
51 | #define INDEX_CREATE_IF_NOT_EXISTS (1 << 4) |
52 | #define INDEX_CREATE_PARTITIONED (1 << 5) |
53 | #define INDEX_CREATE_INVALID (1 << 6) |
54 | |
55 | extern Oid index_create(Relation heapRelation, |
56 | const char *indexRelationName, |
57 | Oid indexRelationId, |
58 | Oid parentIndexRelid, |
59 | Oid parentConstraintId, |
60 | Oid relFileNode, |
61 | IndexInfo *indexInfo, |
62 | List *indexColNames, |
63 | Oid accessMethodObjectId, |
64 | Oid tableSpaceId, |
65 | Oid *collationObjectId, |
66 | Oid *classObjectId, |
67 | int16 *coloptions, |
68 | Datum reloptions, |
69 | bits16 flags, |
70 | bits16 constr_flags, |
71 | bool allow_system_table_mods, |
72 | bool is_internal, |
73 | Oid *constraintId); |
74 | |
75 | #define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY (1 << 0) |
76 | #define INDEX_CONSTR_CREATE_DEFERRABLE (1 << 1) |
77 | #define INDEX_CONSTR_CREATE_INIT_DEFERRED (1 << 2) |
78 | #define INDEX_CONSTR_CREATE_UPDATE_INDEX (1 << 3) |
79 | #define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS (1 << 4) |
80 | |
81 | extern Oid index_concurrently_create_copy(Relation heapRelation, |
82 | Oid oldIndexId, |
83 | const char *newName); |
84 | |
85 | extern void index_concurrently_build(Oid heapRelationId, |
86 | Oid indexRelationId); |
87 | |
88 | extern void index_concurrently_swap(Oid newIndexId, |
89 | Oid oldIndexId, |
90 | const char *oldName); |
91 | |
92 | extern void index_concurrently_set_dead(Oid heapId, |
93 | Oid indexId); |
94 | |
95 | extern ObjectAddress index_constraint_create(Relation heapRelation, |
96 | Oid indexRelationId, |
97 | Oid parentConstraintId, |
98 | IndexInfo *indexInfo, |
99 | const char *constraintName, |
100 | char constraintType, |
101 | bits16 constr_flags, |
102 | bool allow_system_table_mods, |
103 | bool is_internal); |
104 | |
105 | extern void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode); |
106 | |
107 | extern IndexInfo *BuildIndexInfo(Relation index); |
108 | |
109 | extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, |
110 | Oid *collations1, Oid *collations2, |
111 | Oid *opfamilies1, Oid *opfamilies2, |
112 | AttrNumber *attmap, int maplen); |
113 | |
114 | extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii); |
115 | |
116 | extern void FormIndexDatum(IndexInfo *indexInfo, |
117 | TupleTableSlot *slot, |
118 | EState *estate, |
119 | Datum *values, |
120 | bool *isnull); |
121 | |
122 | extern void index_build(Relation heapRelation, |
123 | Relation indexRelation, |
124 | IndexInfo *indexInfo, |
125 | bool isreindex, |
126 | bool parallel); |
127 | |
128 | extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot); |
129 | |
130 | extern void index_set_state_flags(Oid indexId, IndexStateFlagsAction action); |
131 | |
132 | extern void reindex_index(Oid indexId, bool skip_constraint_checks, |
133 | char relpersistence, int options); |
134 | |
135 | /* Flag bits for reindex_relation(): */ |
136 | #define REINDEX_REL_PROCESS_TOAST 0x01 |
137 | #define REINDEX_REL_SUPPRESS_INDEX_USE 0x02 |
138 | #define REINDEX_REL_CHECK_CONSTRAINTS 0x04 |
139 | #define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08 |
140 | #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10 |
141 | |
142 | extern bool reindex_relation(Oid relid, int flags, int options); |
143 | |
144 | extern bool ReindexIsProcessingHeap(Oid heapOid); |
145 | extern bool ReindexIsProcessingIndex(Oid indexOid); |
146 | extern Oid IndexGetRelation(Oid indexId, bool missing_ok); |
147 | |
148 | extern Size EstimateReindexStateSpace(void); |
149 | extern void SerializeReindexState(Size maxsize, char *start_address); |
150 | extern void RestoreReindexState(void *reindexstate); |
151 | |
152 | extern void IndexSetParentIndex(Relation idx, Oid parentOid); |
153 | |
154 | |
155 | /* |
156 | * itemptr_encode - Encode ItemPointer as int64/int8 |
157 | * |
158 | * This representation must produce values encoded as int64 that sort in the |
159 | * same order as their corresponding original TID values would (using the |
160 | * default int8 opclass to produce a result equivalent to the default TID |
161 | * opclass). |
162 | * |
163 | * As noted in validate_index(), this can be significantly faster. |
164 | */ |
165 | static inline int64 |
166 | itemptr_encode(ItemPointer itemptr) |
167 | { |
168 | BlockNumber block = ItemPointerGetBlockNumber(itemptr); |
169 | OffsetNumber offset = ItemPointerGetOffsetNumber(itemptr); |
170 | int64 encoded; |
171 | |
172 | /* |
173 | * Use the 16 least significant bits for the offset. 32 adjacent bits are |
174 | * used for the block number. Since remaining bits are unused, there |
175 | * cannot be negative encoded values (We assume a two's complement |
176 | * representation). |
177 | */ |
178 | encoded = ((uint64) block << 16) | (uint16) offset; |
179 | |
180 | return encoded; |
181 | } |
182 | |
183 | /* |
184 | * itemptr_decode - Decode int64/int8 representation back to ItemPointer |
185 | */ |
186 | static inline void |
187 | itemptr_decode(ItemPointer itemptr, int64 encoded) |
188 | { |
189 | BlockNumber block = (BlockNumber) (encoded >> 16); |
190 | OffsetNumber offset = (OffsetNumber) (encoded & 0xFFFF); |
191 | |
192 | ItemPointerSet(itemptr, block, offset); |
193 | } |
194 | |
195 | #endif /* INDEX_H */ |
196 | |