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-2020, 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 enum ReindexOption
34 {
35  REINDEXOPT_VERBOSE = 1 << 0, /* print progress info */
36  REINDEXOPT_REPORT_PROGRESS = 1 << 1, /* report pgstat progress */
37  REINDEXOPT_MISSING_OK = 1 << 2, /* skip missing relations */
38  REINDEXOPT_CONCURRENTLY = 1 << 3 /* concurrent mode */
40 
41 /* state info for validate_index bulkdelete callback */
42 typedef struct ValidateIndexState
43 {
44  Tuplesortstate *tuplesort; /* for sorting the index TIDs */
45  /* statistics (for debug purposes only): */
46  double htups,
47  itups,
50 
51 extern void index_check_primary_key(Relation heapRel,
52  IndexInfo *indexInfo,
53  bool is_alter_table,
54  IndexStmt *stmt);
55 
56 #define INDEX_CREATE_IS_PRIMARY (1 << 0)
57 #define INDEX_CREATE_ADD_CONSTRAINT (1 << 1)
58 #define INDEX_CREATE_SKIP_BUILD (1 << 2)
59 #define INDEX_CREATE_CONCURRENT (1 << 3)
60 #define INDEX_CREATE_IF_NOT_EXISTS (1 << 4)
61 #define INDEX_CREATE_PARTITIONED (1 << 5)
62 #define INDEX_CREATE_INVALID (1 << 6)
63 
64 extern Oid index_create(Relation heapRelation,
65  const char *indexRelationName,
66  Oid indexRelationId,
67  Oid parentIndexRelid,
68  Oid parentConstraintId,
69  Oid relFileNode,
70  IndexInfo *indexInfo,
71  List *indexColNames,
72  Oid accessMethodObjectId,
73  Oid tableSpaceId,
74  Oid *collationObjectId,
75  Oid *classObjectId,
76  int16 *coloptions,
77  Datum reloptions,
78  bits16 flags,
79  bits16 constr_flags,
80  bool allow_system_table_mods,
81  bool is_internal,
82  Oid *constraintId);
83 
84 #define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY (1 << 0)
85 #define INDEX_CONSTR_CREATE_DEFERRABLE (1 << 1)
86 #define INDEX_CONSTR_CREATE_INIT_DEFERRED (1 << 2)
87 #define INDEX_CONSTR_CREATE_UPDATE_INDEX (1 << 3)
88 #define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS (1 << 4)
89 
90 extern Oid index_concurrently_create_copy(Relation heapRelation,
91  Oid oldIndexId,
92  const char *newName);
93 
94 extern void index_concurrently_build(Oid heapRelationId,
95  Oid indexRelationId);
96 
97 extern void index_concurrently_swap(Oid newIndexId,
98  Oid oldIndexId,
99  const char *oldName);
100 
101 extern void index_concurrently_set_dead(Oid heapId,
102  Oid indexId);
103 
105  Oid indexRelationId,
106  Oid parentConstraintId,
107  IndexInfo *indexInfo,
108  const char *constraintName,
109  char constraintType,
110  bits16 constr_flags,
111  bool allow_system_table_mods,
112  bool is_internal);
113 
114 extern void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode);
115 
117 
119 
120 extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
121  Oid *collations1, Oid *collations2,
122  Oid *opfamilies1, Oid *opfamilies2,
123  AttrMap *attmap);
124 
126 
127 extern void FormIndexDatum(IndexInfo *indexInfo,
128  TupleTableSlot *slot,
129  EState *estate,
130  Datum *values,
131  bool *isnull);
132 
133 extern void index_check_collation_versions(Oid relid);
134 extern void index_update_collation_versions(Oid relid, Oid coll);
135 
136 extern void index_build(Relation heapRelation,
137  Relation indexRelation,
138  IndexInfo *indexInfo,
139  bool isreindex,
140  bool parallel);
141 
142 extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
143 
145 
146 extern Oid IndexGetRelation(Oid indexId, bool missing_ok);
147 
148 extern void reindex_index(Oid indexId, bool skip_constraint_checks,
149  char relpersistence, int options);
150 
151 /* Flag bits for reindex_relation(): */
152 #define REINDEX_REL_PROCESS_TOAST 0x01
153 #define REINDEX_REL_SUPPRESS_INDEX_USE 0x02
154 #define REINDEX_REL_CHECK_CONSTRAINTS 0x04
155 #define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
156 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
157 
158 extern bool reindex_relation(Oid relid, int flags, int options);
159 
160 extern bool ReindexIsProcessingHeap(Oid heapOid);
161 extern bool ReindexIsProcessingIndex(Oid indexOid);
162 
163 extern void ResetReindexState(int nestLevel);
164 extern Size EstimateReindexStateSpace(void);
165 extern void SerializeReindexState(Size maxsize, char *start_address);
166 extern void RestoreReindexState(void *reindexstate);
167 
168 extern void IndexSetParentIndex(Relation idx, Oid parentOid);
169 
170 
171 /*
172  * itemptr_encode - Encode ItemPointer as int64/int8
173  *
174  * This representation must produce values encoded as int64 that sort in the
175  * same order as their corresponding original TID values would (using the
176  * default int8 opclass to produce a result equivalent to the default TID
177  * opclass).
178  *
179  * As noted in validate_index(), this can be significantly faster.
180  */
181 static inline int64
183 {
184  BlockNumber block = ItemPointerGetBlockNumber(itemptr);
185  OffsetNumber offset = ItemPointerGetOffsetNumber(itemptr);
186  int64 encoded;
187 
188  /*
189  * Use the 16 least significant bits for the offset. 32 adjacent bits are
190  * used for the block number. Since remaining bits are unused, there
191  * cannot be negative encoded values (We assume a two's complement
192  * representation).
193  */
194  encoded = ((uint64) block << 16) | (uint16) offset;
195 
196  return encoded;
197 }
198 
199 /*
200  * itemptr_decode - Decode int64/int8 representation back to ItemPointer
201  */
202 static inline void
203 itemptr_decode(ItemPointer itemptr, int64 encoded)
204 {
205  BlockNumber block = (BlockNumber) (encoded >> 16);
206  OffsetNumber offset = (OffsetNumber) (encoded & 0xFFFF);
207 
208  ItemPointerSet(itemptr, block, offset);
209 }
210 
211 #endif /* INDEX_H */
signed short int16
Definition: c.h:416
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:1964
void index_update_collation_versions(Oid relid, Oid coll)
Definition: index.c:1381
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char *newName)
Definition: index.c:1399
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
Definition: index.c:2184
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
Definition: index.c:1606
uint16 bits16
Definition: c.h:437
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
Definition: index.c:1558
void reindex_index(Oid indexId, bool skip_constraint_checks, char relpersistence, int options)
Definition: index.c:3596
void IndexSetParentIndex(Relation idx, Oid parentOid)
Definition: indexcmds.c:3800
void ResetReindexState(int nestLevel)
Definition: index.c:4091
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:686
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:2576
bool ReindexIsProcessingHeap(Oid heapOid)
Definition: index.c:3997
double itups
Definition: index.h:46
Definition: attmap.h:34
uint16 OffsetNumber
Definition: off.h:24
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:4018
Definition: type.h:89
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
Definition: index.c:3342
unsigned short uint16
Definition: c.h:428
Tuplesortstate * tuplesort
Definition: index.h:44
void index_check_collation_versions(Oid relid)
Definition: index.c:1331
IndexInfo * BuildIndexInfo(Relation index)
Definition: index.c:2471
IndexStateFlagsAction
Definition: index.h:24
static int64 itemptr_encode(ItemPointer itemptr)
Definition: index.h:182
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2991
void RestoreReindexState(void *reindexstate)
Definition: index.c:4149
uintptr_t Datum
Definition: postgres.h:367
struct ValidateIndexState ValidateIndexState
static void itemptr_decode(ItemPointer itemptr, int64 encoded)
Definition: index.h:203
double tups_inserted
Definition: index.h:46
size_t Size
Definition: c.h:528
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
Size EstimateReindexStateSpace(void)
Definition: index.c:4120
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Definition: index.c:1903
IndexInfo * BuildDummyIndexInfo(Relation index)
Definition: index.c:2530
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition: index.c:3571
double htups
Definition: index.h:46
static Datum values[MAXATTR]
Definition: bootstrap.c:165
void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table, IndexStmt *stmt)
Definition: index.c:203
ReindexOption
Definition: index.h:33
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:2755
bool reindex_relation(Oid relid, int flags, int options)
Definition: index.c:3849
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:4131
Definition: pg_list.h:50
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
Definition: index.c:2695
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
Definition: index.c:3490