PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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
18#include "nodes/execnodes.h"
19
20
21/*
22 * forward references in this file
23 */
24typedef struct AttrMap AttrMap;
25
26
27#define DEFAULT_INDEX_TYPE "btree"
28
29/* Action code for index_set_state_flags */
37
38/* options for REINDEX */
39typedef struct ReindexParams
40{
41 bits32 options; /* bitmask of REINDEXOPT_* */
42 Oid tablespaceOid; /* New tablespace to move indexes to.
43 * InvalidOid to do nothing. */
45
46/* flag bits for ReindexParams->flags */
47#define REINDEXOPT_VERBOSE 0x01 /* print progress info */
48#define REINDEXOPT_REPORT_PROGRESS 0x02 /* report pgstat progress */
49#define REINDEXOPT_MISSING_OK 0x04 /* skip missing relations */
50#define REINDEXOPT_CONCURRENTLY 0x08 /* concurrent mode */
51
52/* state info for validate_index bulkdelete callback */
53typedef struct ValidateIndexState
54{
55 Tuplesortstate *tuplesort; /* for sorting the index TIDs */
56 /* statistics (for debug purposes only): */
57 double htups,
61
62extern void index_check_primary_key(Relation heapRel,
63 const IndexInfo *indexInfo,
64 bool is_alter_table,
65 const IndexStmt *stmt);
66
67#define INDEX_CREATE_IS_PRIMARY (1 << 0)
68#define INDEX_CREATE_ADD_CONSTRAINT (1 << 1)
69#define INDEX_CREATE_SKIP_BUILD (1 << 2)
70#define INDEX_CREATE_CONCURRENT (1 << 3)
71#define INDEX_CREATE_IF_NOT_EXISTS (1 << 4)
72#define INDEX_CREATE_PARTITIONED (1 << 5)
73#define INDEX_CREATE_INVALID (1 << 6)
74
75extern Oid index_create(Relation heapRelation,
76 const char *indexRelationName,
81 IndexInfo *indexInfo,
82 const List *indexColNames,
85 const Oid *collationIds,
86 const Oid *opclassIds,
87 const Datum *opclassOptions,
88 const int16 *coloptions,
90 Datum reloptions,
91 bits16 flags,
94 bool is_internal,
96
97#define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY (1 << 0)
98#define INDEX_CONSTR_CREATE_DEFERRABLE (1 << 1)
99#define INDEX_CONSTR_CREATE_INIT_DEFERRED (1 << 2)
100#define INDEX_CONSTR_CREATE_UPDATE_INDEX (1 << 3)
101#define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS (1 << 4)
102#define INDEX_CONSTR_CREATE_WITHOUT_OVERLAPS (1 << 5)
103
106 Oid tablespaceOid,
107 const char *newName);
108
111
114 const char *oldName);
115
117 Oid indexId);
118
122 const IndexInfo *indexInfo,
123 const char *constraintName,
124 char constraintType,
127 bool is_internal);
128
129extern void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode);
130
132
134
135extern bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2,
136 const Oid *collations1, const Oid *collations2,
137 const Oid *opfamilies1, const Oid *opfamilies2,
138 const AttrMap *attmap);
139
141
142extern void FormIndexDatum(IndexInfo *indexInfo,
143 TupleTableSlot *slot,
144 EState *estate,
145 Datum *values,
146 bool *isnull);
147
148extern void index_build(Relation heapRelation,
149 Relation indexRelation,
150 IndexInfo *indexInfo,
151 bool isreindex,
152 bool parallel);
153
154extern void validate_index(Oid heapId, Oid indexId, Snapshot snapshot);
155
157
158extern Oid IndexGetRelation(Oid indexId, bool missing_ok);
159
160extern void reindex_index(const ReindexStmt *stmt, Oid indexId,
161 bool skip_constraint_checks, char persistence,
162 const ReindexParams *params);
163
164/* Flag bits for reindex_relation(): */
165#define REINDEX_REL_PROCESS_TOAST 0x01
166#define REINDEX_REL_SUPPRESS_INDEX_USE 0x02
167#define REINDEX_REL_CHECK_CONSTRAINTS 0x04
168#define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
169#define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
170
171extern bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags,
172 const ReindexParams *params);
173
174extern bool ReindexIsProcessingHeap(Oid heapOid);
175extern bool ReindexIsProcessingIndex(Oid indexOid);
176
177extern void ResetReindexState(int nestLevel);
180extern void RestoreReindexState(const void *reindexstate);
181
182extern void IndexSetParentIndex(Relation partitionIdx, Oid parentOid);
183
184
185/*
186 * itemptr_encode - Encode ItemPointer as int64/int8
187 *
188 * This representation must produce values encoded as int64 that sort in the
189 * same order as their corresponding original TID values would (using the
190 * default int8 opclass to produce a result equivalent to the default TID
191 * opclass).
192 *
193 * As noted in validate_index(), this can be significantly faster.
194 */
195static inline int64
197{
198 BlockNumber block = ItemPointerGetBlockNumber(itemptr);
201
202 /*
203 * Use the 16 least significant bits for the offset. 32 adjacent bits are
204 * used for the block number. Since remaining bits are unused, there
205 * cannot be negative encoded values (We assume a two's complement
206 * representation).
207 */
208 encoded = ((uint64) block << 16) | (uint16) offset;
209
210 return encoded;
211}
212
213/*
214 * itemptr_decode - Decode int64/int8 representation back to ItemPointer
215 */
216static inline void
218{
219 BlockNumber block = (BlockNumber) (encoded >> 16);
220 OffsetNumber offset = (OffsetNumber) (encoded & 0xFFFF);
221
222 ItemPointerSet(itemptr, block, offset);
223}
224
225#endif /* INDEX_H */
uint32 BlockNumber
Definition block.h:31
static Datum values[MAXATTR]
Definition bootstrap.c:188
uint16 bits16
Definition c.h:626
int64_t int64
Definition c.h:615
int16_t int16
Definition c.h:613
uint32 bits32
Definition c.h:627
uint64_t uint64
Definition c.h:619
uint16_t uint16
Definition c.h:617
size_t Size
Definition c.h:691
#define stmt
bool ReindexIsProcessingIndex(Oid indexOid)
Definition index.c:4141
void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
Definition index.c:3351
void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
Definition index.c:2123
void ResetReindexState(int nestLevel)
Definition index.c:4214
Oid IndexGetRelation(Oid indexId, bool missing_ok)
Definition index.c:3584
void index_concurrently_set_dead(Oid heapId, Oid indexId)
Definition index.c:1824
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:727
void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)
Definition index.c:1553
static void itemptr_decode(ItemPointer itemptr, int64 encoded)
Definition index.h:217
void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)
Definition index.c:3504
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:2538
IndexInfo * BuildDummyIndexInfo(Relation index)
Definition index.c:2489
bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags, const ReindexParams *params)
Definition index.c:3949
void IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
Definition indexcmds.c:4471
void SerializeReindexState(Size maxsize, char *start_address)
Definition index.c:4254
IndexInfo * BuildIndexInfo(Relation index)
Definition index.c:2429
static int64 itemptr_encode(const ItemPointerData *itemptr)
Definition index.h:196
Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)
Definition index.c:1301
void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)
Definition index.c:2670
void index_check_primary_key(Relation heapRel, const IndexInfo *indexInfo, bool is_alter_table, const IndexStmt *stmt)
Definition index.c:203
bool ReindexIsProcessingHeap(Oid heapOid)
Definition index.c:4120
IndexStateFlagsAction
Definition index.h:31
@ INDEX_CREATE_SET_VALID
Definition index.h:33
@ INDEX_DROP_CLEAR_VALID
Definition index.h:34
@ INDEX_DROP_SET_DEAD
Definition index.h:35
@ INDEX_CREATE_SET_READY
Definition index.h:32
void RestoreReindexState(const void *reindexstate)
Definition index.c:4272
void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)
Definition index.c:3003
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:1886
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition index.c:2731
void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)
Definition index.c:1486
Size EstimateReindexStateSpace(void)
Definition index.c:4243
void reindex_index(const ReindexStmt *stmt, Oid indexId, bool skip_constraint_checks, char persistence, const ReindexParams *params)
Definition index.c:3609
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
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
Oid RelFileNumber
Definition relpath.h:25
Definition pg_list.h:54
Oid tablespaceOid
Definition index.h:42
bits32 options
Definition index.h:41
Tuplesortstate * tuplesort
Definition index.h:55
double tups_inserted
Definition index.h:59
Definition type.h:96