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 /* 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,
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 
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 
108 
110 
111 extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
112  Oid *collations1, Oid *collations2,
113  Oid *opfamilies1, Oid *opfamilies2,
114  AttrMap *attmap);
115 
117 
118 extern void FormIndexDatum(IndexInfo *indexInfo,
119  TupleTableSlot *slot,
120  EState *estate,
121  Datum *values,
122  bool *isnull);
123 
124 extern void index_build(Relation heapRelation,
125  Relation indexRelation,
126  IndexInfo *indexInfo,
127  bool isreindex,
128  bool parallel);
129 
130 extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
131 
133 
134 extern void reindex_index(Oid indexId, bool skip_constraint_checks,
135  char relpersistence, int options);
136 
137 /* Flag bits for reindex_relation(): */
138 #define REINDEX_REL_PROCESS_TOAST 0x01
139 #define REINDEX_REL_SUPPRESS_INDEX_USE 0x02
140 #define REINDEX_REL_CHECK_CONSTRAINTS 0x04
141 #define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
142 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
143 
144 extern bool reindex_relation(Oid relid, int flags, int options);
145 
146 extern bool ReindexIsProcessingHeap(Oid heapOid);
147 extern bool ReindexIsProcessingIndex(Oid indexOid);
148 extern Oid IndexGetRelation(Oid indexId, bool missing_ok);
149 
150 extern Size EstimateReindexStateSpace(void);
151 extern void SerializeReindexState(Size maxsize, char *start_address);
152 extern void RestoreReindexState(void *reindexstate);
153 
154 extern void IndexSetParentIndex(Relation idx, Oid parentOid);
155 
156 
157 /*
158  * itemptr_encode - Encode ItemPointer as int64/int8
159  *
160  * This representation must produce values encoded as int64 that sort in the
161  * same order as their corresponding original TID values would (using the
162  * default int8 opclass to produce a result equivalent to the default TID
163  * opclass).
164  *
165  * As noted in validate_index(), this can be significantly faster.
166  */
167 static inline int64
169 {
170  BlockNumber block = ItemPointerGetBlockNumber(itemptr);
171  OffsetNumber offset = ItemPointerGetOffsetNumber(itemptr);
172  int64 encoded;
173 
174  /*
175  * Use the 16 least significant bits for the offset. 32 adjacent bits are
176  * used for the block number. Since remaining bits are unused, there
177  * cannot be negative encoded values (We assume a two's complement
178  * representation).
179  */
180  encoded = ((uint64) block << 16) | (uint16) offset;
181 
182  return encoded;
183 }
184 
185 /*
186  * itemptr_decode - Decode int64/int8 representation back to ItemPointer
187  */
188 static inline void
189 itemptr_decode(ItemPointer itemptr, int64 encoded)
190 {
191  BlockNumber block = (BlockNumber) (encoded >> 16);
192  OffsetNumber offset = (OffsetNumber) (encoded & 0xFFFF);
193 
194  ItemPointerSet(itemptr, block, offset);
195 }
196 
197 #endif /* INDEX_H */
signed short int16
Definition: c.h:346
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:1787
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char *newName)
Definition: index.c:1240
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
Definition: index.c:2006
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
Definition: index.c:1447
uint16 bits16
Definition: c.h:367
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
Definition: index.c:1399
void reindex_index(Oid indexId, bool skip_constraint_checks, char relpersistence, int options)
Definition: index.c:3404
void IndexSetParentIndex(Relation idx, Oid parentOid)
Definition: indexcmds.c:3361
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:690
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:263
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:2387
bool ReindexIsProcessingHeap(Oid heapOid)
Definition: index.c:3770
double itups
Definition: index.h:37
Definition: attmap.h:34
uint16 OffsetNumber
Definition: off.h:24
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3791
Definition: type.h:89
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
Definition: index.c:3144
unsigned short uint16
Definition: c.h:358
char relpersistence
Definition: pg_class.h:78
Tuplesortstate * tuplesort
Definition: index.h:35
IndexInfo * BuildIndexInfo(Relation index)
Definition: index.c:2284
IndexStateFlagsAction
Definition: index.h:24
static int64 itemptr_encode(ItemPointer itemptr)
Definition: index.h:168
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2793
void RestoreReindexState(void *reindexstate)
Definition: index.c:3904
uintptr_t Datum
Definition: postgres.h:367
struct ValidateIndexState ValidateIndexState
static void itemptr_decode(ItemPointer itemptr, int64 encoded)
Definition: index.h:189
double tups_inserted
Definition: index.h:37
size_t Size
Definition: c.h:467
#define ItemPointerGetOffsetNumber(pointer)
Definition: itemptr.h:117
Size EstimateReindexStateSpace(void)
Definition: index.c:3875
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Definition: index.c:1726
IndexInfo * BuildDummyIndexInfo(Relation index)
Definition: index.c:2341
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition: index.c:3379
double htups
Definition: index.h:37
static Datum values[MAXATTR]
Definition: bootstrap.c:167
void index_check_primary_key(Relation heapRel, IndexInfo *indexInfo, bool is_alter_table, IndexStmt *stmt)
Definition: index.c:200
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:2566
bool reindex_relation(Oid relid, int flags, int options)
Definition: index.c:3637
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:3886
Definition: pg_list.h:50
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
Definition: index.c:2506
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
Definition: index.c:3300