PostgreSQL Source Code  git master
index.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * index.h
4  * prototypes for catalog/index.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/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 {
31 
32 /* options for REINDEX */
33 typedef struct ReindexParams
34 {
35  bits32 options; /* bitmask of REINDEXOPT_* */
36  Oid tablespaceOid; /* New tablespace to move indexes to.
37  * InvalidOid to do nothing. */
39 
40 /* flag bits for ReindexParams->flags */
41 #define REINDEXOPT_VERBOSE 0x01 /* print progress info */
42 #define REINDEXOPT_REPORT_PROGRESS 0x02 /* report pgstat progress */
43 #define REINDEXOPT_MISSING_OK 0x04 /* skip missing relations */
44 #define REINDEXOPT_CONCURRENTLY 0x08 /* concurrent mode */
45 
46 /* state info for validate_index bulkdelete callback */
47 typedef struct ValidateIndexState
48 {
49  Tuplesortstate *tuplesort; /* for sorting the index TIDs */
50  /* statistics (for debug purposes only): */
51  double htups,
52  itups,
55 
56 extern void index_check_primary_key(Relation heapRel,
57  IndexInfo *indexInfo,
58  bool is_alter_table,
59  IndexStmt *stmt);
60 
61 #define INDEX_CREATE_IS_PRIMARY (1 << 0)
62 #define INDEX_CREATE_ADD_CONSTRAINT (1 << 1)
63 #define INDEX_CREATE_SKIP_BUILD (1 << 2)
64 #define INDEX_CREATE_CONCURRENT (1 << 3)
65 #define INDEX_CREATE_IF_NOT_EXISTS (1 << 4)
66 #define INDEX_CREATE_PARTITIONED (1 << 5)
67 #define INDEX_CREATE_INVALID (1 << 6)
68 
69 extern Oid index_create(Relation heapRelation,
70  const char *indexRelationName,
71  Oid indexRelationId,
72  Oid parentIndexRelid,
73  Oid parentConstraintId,
74  Oid relFileNode,
75  IndexInfo *indexInfo,
76  List *indexColNames,
77  Oid accessMethodObjectId,
78  Oid tableSpaceId,
79  Oid *collationObjectId,
80  Oid *classObjectId,
81  int16 *coloptions,
82  Datum reloptions,
83  bits16 flags,
84  bits16 constr_flags,
85  bool allow_system_table_mods,
86  bool is_internal,
87  Oid *constraintId);
88 
89 #define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY (1 << 0)
90 #define INDEX_CONSTR_CREATE_DEFERRABLE (1 << 1)
91 #define INDEX_CONSTR_CREATE_INIT_DEFERRED (1 << 2)
92 #define INDEX_CONSTR_CREATE_UPDATE_INDEX (1 << 3)
93 #define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS (1 << 4)
94 
95 extern Oid index_concurrently_create_copy(Relation heapRelation,
96  Oid oldIndexId,
98  const char *newName);
99 
100 extern void index_concurrently_build(Oid heapRelationId,
101  Oid indexRelationId);
102 
103 extern void index_concurrently_swap(Oid newIndexId,
104  Oid oldIndexId,
105  const char *oldName);
106 
107 extern void index_concurrently_set_dead(Oid heapId,
108  Oid indexId);
109 
111  Oid indexRelationId,
112  Oid parentConstraintId,
113  IndexInfo *indexInfo,
114  const char *constraintName,
115  char constraintType,
116  bits16 constr_flags,
117  bool allow_system_table_mods,
118  bool is_internal);
119 
120 extern void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode);
121 
123 
125 
126 extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
127  Oid *collations1, Oid *collations2,
128  Oid *opfamilies1, Oid *opfamilies2,
129  AttrMap *attmap);
130 
132 
133 extern void FormIndexDatum(IndexInfo *indexInfo,
134  TupleTableSlot *slot,
135  EState *estate,
136  Datum *values,
137  bool *isnull);
138 
139 extern void index_build(Relation heapRelation,
140  Relation indexRelation,
141  IndexInfo *indexInfo,
142  bool isreindex,
143  bool parallel);
144 
145 extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
146 
148 
149 extern Oid IndexGetRelation(Oid indexId, bool missing_ok);
150 
151 extern void reindex_index(Oid indexId, bool skip_constraint_checks,
152  char relpersistence, ReindexParams *params);
153 
154 /* Flag bits for reindex_relation(): */
155 #define REINDEX_REL_PROCESS_TOAST 0x01
156 #define REINDEX_REL_SUPPRESS_INDEX_USE 0x02
157 #define REINDEX_REL_CHECK_CONSTRAINTS 0x04
158 #define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
159 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
160 
161 extern bool reindex_relation(Oid relid, int flags, ReindexParams *params);
162 
163 extern bool ReindexIsProcessingHeap(Oid heapOid);
164 extern bool ReindexIsProcessingIndex(Oid indexOid);
165 
166 extern void ResetReindexState(int nestLevel);
167 extern Size EstimateReindexStateSpace(void);
168 extern void SerializeReindexState(Size maxsize, char *start_address);
169 extern void RestoreReindexState(void *reindexstate);
170 
171 extern void IndexSetParentIndex(Relation idx, Oid parentOid);
172 
173 
174 /*
175  * itemptr_encode - Encode ItemPointer as int64/int8
176  *
177  * This representation must produce values encoded as int64 that sort in the
178  * same order as their corresponding original TID values would (using the
179  * default int8 opclass to produce a result equivalent to the default TID
180  * opclass).
181  *
182  * As noted in validate_index(), this can be significantly faster.
183  */
184 static inline int64
186 {
187  BlockNumber block = ItemPointerGetBlockNumber(itemptr);
188  OffsetNumber offset = ItemPointerGetOffsetNumber(itemptr);
189  int64 encoded;
190 
191  /*
192  * Use the 16 least significant bits for the offset. 32 adjacent bits are
193  * used for the block number. Since remaining bits are unused, there
194  * cannot be negative encoded values (We assume a two's complement
195  * representation).
196  */
197  encoded = ((uint64) block << 16) | (uint16) offset;
198 
199  return encoded;
200 }
201 
202 /*
203  * itemptr_decode - Decode int64/int8 representation back to ItemPointer
204  */
205 static inline void
206 itemptr_decode(ItemPointer itemptr, int64 encoded)
207 {
208  BlockNumber block = (BlockNumber) (encoded >> 16);
209  OffsetNumber offset = (OffsetNumber) (encoded & 0xFFFF);
210 
211  ItemPointerSet(itemptr, block, offset);
212 }
213 
214 #endif /* INDEX_H */
signed short int16
Definition: c.h:428
ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, bool allow_system_table_mods, bool is_internal)
Definition: index.c:1871
bool reindex_relation(Oid relid, int flags, ReindexParams *params)
Definition: index.c:3795
struct ReindexParams ReindexParams
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
Definition: index.c:2091
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
Definition: index.c:1461
uint16 bits16
Definition: c.h:449
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
Definition: index.c:1413
void IndexSetParentIndex(Relation idx, Oid parentOid)
Definition: indexcmds.c:4014
void ResetReindexState(int nestLevel)
Definition: index.c:4042
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
Definition: index.c:1253
Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, Oid relFileNode, IndexInfo *indexInfo, List *indexColNames, Oid accessMethodObjectId, Oid tableSpaceId, Oid *collationObjectId, Oid *classObjectId, int16 *coloptions, Datum reloptions, bits16 flags, bits16 constr_flags, bool allow_system_table_mods, bool is_internal, Oid *constraintId)
Definition: index.c:698
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
uint32 BlockNumber
Definition: block.h:31
unsigned int Oid
Definition: postgres_ext.h:31
bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, Oid *collations1, Oid *collations2, Oid *opfamilies1, Oid *opfamilies2, AttrMap *attmap)
Definition: index.c:2483
bool ReindexIsProcessingHeap(Oid heapOid)
Definition: index.c:3948
Definition: attmap.h:34
uint16 OffsetNumber
Definition: off.h:24
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3969
Definition: type.h:89
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
Definition: index.c:3246
unsigned short uint16
Definition: c.h:440
Tuplesortstate * tuplesort
Definition: index.h:49
Oid tablespaceOid
Definition: index.h:36
IndexInfo * BuildIndexInfo(Relation index)
Definition: index.c:2378
IndexStateFlagsAction
Definition: index.h:24
static int64 itemptr_encode(ItemPointer itemptr)
Definition: index.h:185
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2898
void RestoreReindexState(void *reindexstate)
Definition: index.c:4100
uintptr_t Datum
Definition: postgres.h:411
void reindex_index(Oid indexId, bool skip_constraint_checks, char relpersistence, ReindexParams *params)
Definition: index.c:3500
struct ValidateIndexState ValidateIndexState
static void itemptr_decode(ItemPointer itemptr, int64 encoded)
Definition: index.h:206
uint32 bits32
Definition: c.h:450
double tups_inserted
Definition: index.h:51
bits32 options
Definition: index.h:35
size_t Size
Definition: c.h:540
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
Size EstimateReindexStateSpace(void)
Definition: index.c:4071
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Definition: index.c:1810
IndexInfo * BuildDummyIndexInfo(Relation index)
Definition: index.c:2437
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition: index.c:3475
static Datum values[MAXATTR]
Definition: bootstrap.c:156
void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table, IndexStmt *stmt)
Definition: index.c:203
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:2662
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:4082
Definition: pg_list.h:50
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
Definition: index.c:2602
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
Definition: index.c:3394