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-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 {
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 
109 extern bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2,
110  Oid *collations1, Oid *collations2,
111  Oid *opfamilies1, Oid *opfamilies2,
112  AttrNumber *attmap, int maplen);
113 
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 
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
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 */
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:1788
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, const char *newName)
Definition: index.c:1241
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
Definition: index.c:2007
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
Definition: index.c:1448
uint16 bits16
Definition: c.h:367
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
Definition: index.c:1400
void reindex_index(Oid indexId, bool skip_constraint_checks, char relpersistence, int options)
Definition: index.c:3355
void IndexSetParentIndex(Relation idx, Oid parentOid)
Definition: indexcmds.c:3363
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:691
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 ReindexIsProcessingHeap(Oid heapOid)
Definition: index.c:3721
double itups
Definition: index.h:37
uint16 OffsetNumber
Definition: off.h:24
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3742
Definition: type.h:89
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
Definition: index.c:3095
unsigned short uint16
Definition: c.h:358
char relpersistence
Definition: pg_class.h:78
Tuplesortstate * tuplesort
Definition: index.h:35
bool CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, Oid *collations1, Oid *collations2, Oid *opfamilies1, Oid *opfamilies2, AttrNumber *attmap, int maplen)
Definition: index.c:2338
IndexInfo * BuildIndexInfo(Relation index)
Definition: index.c:2285
IndexStateFlagsAction
Definition: index.h:24
static int64 itemptr_encode(ItemPointer itemptr)
Definition: index.h:166
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2744
void RestoreReindexState(void *reindexstate)
Definition: index.c:3855
uintptr_t Datum
Definition: postgres.h:367
struct ValidateIndexState ValidateIndexState
static void itemptr_decode(ItemPointer itemptr, int64 encoded)
Definition: index.h:187
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:3826
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Definition: index.c:1727
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition: index.c:3330
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:2517
bool reindex_relation(Oid relid, int flags, int options)
Definition: index.c:3588
#define ItemPointerGetBlockNumber(pointer)
Definition: itemptr.h:98
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:3837
Definition: pg_list.h:50
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
Definition: index.c:2457
int16 AttrNumber
Definition: attnum.h:21
#define ItemPointerSet(pointer, blockNumber, offNum)
Definition: itemptr.h:127
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
Definition: index.c:3251