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-2024, 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,
55 
56 extern void index_check_primary_key(Relation heapRel,
57  const IndexInfo *indexInfo,
58  bool is_alter_table,
59  const 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  RelFileNumber relFileNumber,
75  IndexInfo *indexInfo,
76  const List *indexColNames,
77  Oid accessMethodId,
78  Oid tableSpaceId,
79  const Oid *collationIds,
80  const Oid *opclassIds,
81  const Datum *opclassOptions,
82  const int16 *coloptions,
83  const NullableDatum *stattargets,
84  Datum reloptions,
85  bits16 flags,
86  bits16 constr_flags,
87  bool allow_system_table_mods,
88  bool is_internal,
89  Oid *constraintId);
90 
91 #define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY (1 << 0)
92 #define INDEX_CONSTR_CREATE_DEFERRABLE (1 << 1)
93 #define INDEX_CONSTR_CREATE_INIT_DEFERRED (1 << 2)
94 #define INDEX_CONSTR_CREATE_UPDATE_INDEX (1 << 3)
95 #define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS (1 << 4)
96 
97 extern Oid index_concurrently_create_copy(Relation heapRelation,
98  Oid oldIndexId,
99  Oid tablespaceOid,
100  const char *newName);
101 
102 extern void index_concurrently_build(Oid heapRelationId,
103  Oid indexRelationId);
104 
105 extern void index_concurrently_swap(Oid newIndexId,
106  Oid oldIndexId,
107  const char *oldName);
108 
109 extern void index_concurrently_set_dead(Oid heapId,
110  Oid indexId);
111 
113  Oid indexRelationId,
114  Oid parentConstraintId,
115  const IndexInfo *indexInfo,
116  const char *constraintName,
117  char constraintType,
118  bits16 constr_flags,
119  bool allow_system_table_mods,
120  bool is_internal);
121 
122 extern void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode);
123 
125 
127 
128 extern bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2,
129  const Oid *collations1, const Oid *collations2,
130  const Oid *opfamilies1, const Oid *opfamilies2,
131  const AttrMap *attmap);
132 
134 
135 extern void FormIndexDatum(IndexInfo *indexInfo,
136  TupleTableSlot *slot,
137  EState *estate,
138  Datum *values,
139  bool *isnull);
140 
141 extern void index_build(Relation heapRelation,
142  Relation indexRelation,
143  IndexInfo *indexInfo,
144  bool isreindex,
145  bool parallel);
146 
147 extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
148 
150 
151 extern Oid IndexGetRelation(Oid indexId, bool missing_ok);
152 
153 extern void reindex_index(const ReindexStmt *stmt, Oid indexId,
154  bool skip_constraint_checks, char persistence,
155  const ReindexParams *params);
156 
157 /* Flag bits for reindex_relation(): */
158 #define REINDEX_REL_PROCESS_TOAST 0x01
159 #define REINDEX_REL_SUPPRESS_INDEX_USE 0x02
160 #define REINDEX_REL_CHECK_CONSTRAINTS 0x04
161 #define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
162 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
163 
164 extern bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags,
165  const ReindexParams *params);
166 
167 extern bool ReindexIsProcessingHeap(Oid heapOid);
168 extern bool ReindexIsProcessingIndex(Oid indexOid);
169 
170 extern void ResetReindexState(int nestLevel);
171 extern Size EstimateReindexStateSpace(void);
172 extern void SerializeReindexState(Size maxsize, char *start_address);
173 extern void RestoreReindexState(const void *reindexstate);
174 
175 extern void IndexSetParentIndex(Relation partitionIdx, Oid parentOid);
176 
177 
178 /*
179  * itemptr_encode - Encode ItemPointer as int64/int8
180  *
181  * This representation must produce values encoded as int64 that sort in the
182  * same order as their corresponding original TID values would (using the
183  * default int8 opclass to produce a result equivalent to the default TID
184  * opclass).
185  *
186  * As noted in validate_index(), this can be significantly faster.
187  */
188 static inline int64
190 {
191  BlockNumber block = ItemPointerGetBlockNumber(itemptr);
192  OffsetNumber offset = ItemPointerGetOffsetNumber(itemptr);
193  int64 encoded;
194 
195  /*
196  * Use the 16 least significant bits for the offset. 32 adjacent bits are
197  * used for the block number. Since remaining bits are unused, there
198  * cannot be negative encoded values (We assume a two's complement
199  * representation).
200  */
201  encoded = ((uint64) block << 16) | (uint16) offset;
202 
203  return encoded;
204 }
205 
206 /*
207  * itemptr_decode - Decode int64/int8 representation back to ItemPointer
208  */
209 static inline void
210 itemptr_decode(ItemPointer itemptr, int64 encoded)
211 {
212  BlockNumber block = (BlockNumber) (encoded >> 16);
213  OffsetNumber offset = (OffsetNumber) (encoded & 0xFFFF);
214 
215  ItemPointerSet(itemptr, block, offset);
216 }
217 
218 #endif /* INDEX_H */
uint32 BlockNumber
Definition: block.h:31
static Datum values[MAXATTR]
Definition: bootstrap.c:152
unsigned short uint16
Definition: c.h:505
uint16 bits16
Definition: c.h:514
signed short int16
Definition: c.h:493
uint32 bits32
Definition: c.h:515
size_t Size
Definition: c.h:605
#define stmt
Definition: indent_codes.h:59
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:4072
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
Definition: index.c:3290
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
Definition: index.c:2113
void ResetReindexState(int nestLevel)
Definition: index.c:4145
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition: index.c:3523
struct ValidateIndexState ValidateIndexState
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Definition: index.c:1819
Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, RelFileNumber relFileNumber, IndexInfo *indexInfo, const List *indexColNames, Oid accessMethodId, Oid tableSpaceId, const Oid *collationIds, const Oid *opclassIds, const Datum *opclassOptions, const int16 *coloptions, const NullableDatum *stattargets, Datum reloptions, bits16 flags, bits16 constr_flags, bool allow_system_table_mods, bool is_internal, Oid *constraintId)
Definition: index.c:724
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
Definition: index.c:1548
static void itemptr_decode(ItemPointer itemptr, int64 encoded)
Definition: index.h:210
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
Definition: index.c:3443
bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2, const Oid *collations1, const Oid *collations2, const Oid *opfamilies1, const Oid *opfamilies2, const AttrMap *attmap)
Definition: index.c:2510
IndexInfo * BuildDummyIndexInfo(Relation index)
Definition: index.c:2462
bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags, const ReindexParams *params)
Definition: index.c:3888
static int64 itemptr_encode(ItemPointer itemptr)
Definition: index.h:189
void IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
Definition: indexcmds.c:4276
void SerializeReindexState(Size maxsize, char *start_address)
Definition: index.c:4185
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
Definition: index.c:1297
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
Definition: index.c:2641
void index_check_primary_key(Relation heapRel, const IndexInfo *indexInfo, bool is_alter_table, const IndexStmt *stmt)
Definition: index.c:201
bool ReindexIsProcessingHeap(Oid heapOid)
Definition: index.c:4051
struct ReindexParams ReindexParams
IndexStateFlagsAction
Definition: index.h:25
@ INDEX_CREATE_SET_VALID
Definition: index.h:27
@ INDEX_DROP_CLEAR_VALID
Definition: index.h:28
@ INDEX_DROP_SET_DEAD
Definition: index.h:29
@ INDEX_CREATE_SET_READY
Definition: index.h:26
void RestoreReindexState(const void *reindexstate)
Definition: index.c:4203
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition: index.c:2941
ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, const IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, bool allow_system_table_mods, bool is_internal)
Definition: index.c:1880
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:2701
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
Definition: index.c:1481
Size EstimateReindexStateSpace(void)
Definition: index.c:4174
IndexInfo * BuildIndexInfo(Relation index)
Definition: index.c:2403
void reindex_index(const ReindexStmt *stmt, Oid indexId, bool skip_constraint_checks, char persistence, const ReindexParams *params)
Definition: index.c:3548
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
Definition: itemptr.h:135
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
Definition: itemptr.h:124
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
uint16 OffsetNumber
Definition: off.h:24
uintptr_t Datum
Definition: postgres.h:64
unsigned int Oid
Definition: postgres_ext.h:31
Oid RelFileNumber
Definition: relpath.h:25
Definition: attmap.h:35
Definition: pg_list.h:54
Oid tablespaceOid
Definition: index.h:36
bits32 options
Definition: index.h:35
Tuplesortstate * tuplesort
Definition: index.h:49
double tups_inserted
Definition: index.h:53
double htups
Definition: index.h:51
double itups
Definition: index.h:52
Definition: type.h:95