1 /*-------------------------------------------------------------------------
4 * prototypes for catalog/index.c.
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/catalog/index.h
12 *-------------------------------------------------------------------------
17 #include "catalog/objectaddress.h"
18 #include "nodes/execnodes.h"
21 #define DEFAULT_INDEX_TYPE "btree"
23 /* Action code for index_set_state_flags */
26 INDEX_CREATE_SET_READY
,
27 INDEX_CREATE_SET_VALID
,
28 INDEX_DROP_CLEAR_VALID
,
30 } IndexStateFlagsAction
;
32 /* options for REINDEX */
33 typedef struct ReindexParams
35 bits32 options
; /* bitmask of REINDEXOPT_* */
36 Oid tablespaceOid
; /* New tablespace to move indexes to.
37 * InvalidOid to do nothing. */
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 */
46 /* state info for validate_index bulkdelete callback */
47 typedef struct ValidateIndexState
49 Tuplesortstate
*tuplesort
; /* for sorting the index TIDs */
50 /* statistics (for debug purposes only): */
56 extern void index_check_primary_key(Relation heapRel
,
57 const IndexInfo
*indexInfo
,
59 const IndexStmt
*stmt
);
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)
69 extern Oid
index_create(Relation heapRelation
,
70 const char *indexRelationName
,
73 Oid parentConstraintId
,
74 RelFileNumber relFileNumber
,
76 const List
*indexColNames
,
79 const Oid
*collationIds
,
80 const Oid
*opclassIds
,
81 const Datum
*opclassOptions
,
82 const int16
*coloptions
,
83 const NullableDatum
*stattargets
,
87 bool allow_system_table_mods
,
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 #define INDEX_CONSTR_CREATE_WITHOUT_OVERLAPS (1 << 5)
98 extern Oid
index_concurrently_create_copy(Relation heapRelation
,
101 const char *newName
);
103 extern void index_concurrently_build(Oid heapRelationId
,
104 Oid indexRelationId
);
106 extern void index_concurrently_swap(Oid newIndexId
,
108 const char *oldName
);
110 extern void index_concurrently_set_dead(Oid heapId
,
113 extern ObjectAddress
index_constraint_create(Relation heapRelation
,
115 Oid parentConstraintId
,
116 const IndexInfo
*indexInfo
,
117 const char *constraintName
,
120 bool allow_system_table_mods
,
123 extern void index_drop(Oid indexId
, bool concurrent
, bool concurrent_lock_mode
);
125 extern IndexInfo
*BuildIndexInfo(Relation index
);
127 extern IndexInfo
*BuildDummyIndexInfo(Relation index
);
129 extern bool CompareIndexInfo(const IndexInfo
*info1
, const IndexInfo
*info2
,
130 const Oid
*collations1
, const Oid
*collations2
,
131 const Oid
*opfamilies1
, const Oid
*opfamilies2
,
132 const AttrMap
*attmap
);
134 extern void BuildSpeculativeIndexInfo(Relation index
, IndexInfo
*ii
);
136 extern void FormIndexDatum(IndexInfo
*indexInfo
,
137 TupleTableSlot
*slot
,
142 extern void index_build(Relation heapRelation
,
143 Relation indexRelation
,
144 IndexInfo
*indexInfo
,
148 extern void validate_index(Oid heapId
, Oid indexId
, Snapshot snapshot
);
150 extern void index_set_state_flags(Oid indexId
, IndexStateFlagsAction action
);
152 extern Oid
IndexGetRelation(Oid indexId
, bool missing_ok
);
154 extern void reindex_index(const ReindexStmt
*stmt
, Oid indexId
,
155 bool skip_constraint_checks
, char persistence
,
156 const ReindexParams
*params
);
158 /* Flag bits for reindex_relation(): */
159 #define REINDEX_REL_PROCESS_TOAST 0x01
160 #define REINDEX_REL_SUPPRESS_INDEX_USE 0x02
161 #define REINDEX_REL_CHECK_CONSTRAINTS 0x04
162 #define REINDEX_REL_FORCE_INDEXES_UNLOGGED 0x08
163 #define REINDEX_REL_FORCE_INDEXES_PERMANENT 0x10
165 extern bool reindex_relation(const ReindexStmt
*stmt
, Oid relid
, int flags
,
166 const ReindexParams
*params
);
168 extern bool ReindexIsProcessingHeap(Oid heapOid
);
169 extern bool ReindexIsProcessingIndex(Oid indexOid
);
171 extern void ResetReindexState(int nestLevel
);
172 extern Size
EstimateReindexStateSpace(void);
173 extern void SerializeReindexState(Size maxsize
, char *start_address
);
174 extern void RestoreReindexState(const void *reindexstate
);
176 extern void IndexSetParentIndex(Relation partitionIdx
, Oid parentOid
);
180 * itemptr_encode - Encode ItemPointer as int64/int8
182 * This representation must produce values encoded as int64 that sort in the
183 * same order as their corresponding original TID values would (using the
184 * default int8 opclass to produce a result equivalent to the default TID
187 * As noted in validate_index(), this can be significantly faster.
190 itemptr_encode(ItemPointer itemptr
)
192 BlockNumber block
= ItemPointerGetBlockNumber(itemptr
);
193 OffsetNumber offset
= ItemPointerGetOffsetNumber(itemptr
);
197 * Use the 16 least significant bits for the offset. 32 adjacent bits are
198 * used for the block number. Since remaining bits are unused, there
199 * cannot be negative encoded values (We assume a two's complement
202 encoded
= ((uint64
) block
<< 16) | (uint16
) offset
;
208 * itemptr_decode - Decode int64/int8 representation back to ItemPointer
211 itemptr_decode(ItemPointer itemptr
, int64 encoded
)
213 BlockNumber block
= (BlockNumber
) (encoded
>> 16);
214 OffsetNumber offset
= (OffsetNumber
) (encoded
& 0xFFFF);
216 ItemPointerSet(itemptr
, block
, offset
);