PostgreSQL Source Code git master
Loading...
Searching...
No Matches
genam.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * genam.h
4 * POSTGRES generalized index access method definitions.
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/access/genam.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef GENAM_H
15#define GENAM_H
16
17#include "access/htup.h"
18#include "access/sdir.h"
19#include "access/skey.h"
21#include "storage/buf.h"
22#include "storage/lockdefs.h"
23#include "utils/snapshot.h"
24
25
26/*
27 * forward references in this file
28 */
29typedef struct IndexInfo IndexInfo;
30typedef struct RelationData *Relation;
31typedef struct TIDBitmap TIDBitmap;
33
34
35/*
36 * Struct for statistics returned by ambuild
37 */
38typedef struct IndexBuildResult
39{
40 double heap_tuples; /* # of tuples seen in parent table */
41 double index_tuples; /* # of tuples inserted into index */
43
44/*
45 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
46 *
47 * num_heap_tuples is accurate only when estimated_count is false;
48 * otherwise it's just an estimate (currently, the estimate is the
49 * prior value of the relation's pg_class.reltuples field, so it could
50 * even be -1). It will always just be an estimate during ambulkdelete.
51 */
52typedef struct IndexVacuumInfo
53{
54 Relation index; /* the index being vacuumed */
55 Relation heaprel; /* the heap relation the index belongs to */
56 bool analyze_only; /* ANALYZE (without any actual vacuum) */
57 bool report_progress; /* emit progress.h status reports */
58 bool estimated_count; /* num_heap_tuples is an estimate */
59 int message_level; /* ereport level for progress messages */
60 double num_heap_tuples; /* tuples remaining in heap */
61 BufferAccessStrategy strategy; /* access strategy for reads */
63
64/*
65 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
66 *
67 * This struct is normally allocated by the first ambulkdelete call and then
68 * passed along through subsequent ones until amvacuumcleanup; however,
69 * amvacuumcleanup must be prepared to allocate it in the case where no
70 * ambulkdelete calls were made (because no tuples needed deletion).
71 * Note that an index AM could choose to return a larger struct
72 * of which this is just the first field; this provides a way for ambulkdelete
73 * to communicate additional private data to amvacuumcleanup.
74 *
75 * Note: pages_newly_deleted is the number of pages in the index that were
76 * deleted by the current vacuum operation. pages_deleted and pages_free
77 * refer to free space within the index file.
78 *
79 * Note: Some index AMs may compute num_index_tuples by reference to
80 * num_heap_tuples, in which case they should copy the estimated_count field
81 * from IndexVacuumInfo.
82 */
84{
85 BlockNumber num_pages; /* pages remaining in index */
86 bool estimated_count; /* num_index_tuples is an estimate */
87 double num_index_tuples; /* tuples remaining */
88 double tuples_removed; /* # removed during vacuum operation */
89 BlockNumber pages_newly_deleted; /* # pages marked deleted by us */
90 BlockNumber pages_deleted; /* # pages marked deleted (could be by us) */
91 BlockNumber pages_free; /* # pages available for reuse */
93
94/* Typedef for callback function to determine if a tuple is bulk-deletable */
95typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
96
97/* struct definitions appear in relscan.h */
100
102
103/*
104 * Enumeration specifying the type of uniqueness check to perform in
105 * index_insert().
106 *
107 * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
108 * blocking to see if a conflicting transaction commits.
109 *
110 * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
111 * insertion time. The index AM should test if the tuple is unique, but
112 * should not throw error, block, or prevent the insertion if the tuple
113 * appears not to be unique. We'll recheck later when it is time for the
114 * constraint to be enforced. The AM must return true if the tuple is
115 * known unique, false if it is possibly non-unique. In the "true" case
116 * it is safe to omit the later recheck.
117 *
118 * When it is time to recheck the deferred constraint, a pseudo-insertion
119 * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
120 * index in this case, so it should not be inserted again. Rather, just
121 * check for conflicting live tuples (possibly blocking).
122 */
124{
125 UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
126 UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
127 UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
128 UNIQUE_CHECK_EXISTING, /* Check if existing tuple is unique */
130
131
132/* Nullable "ORDER BY col op const" distance */
138
139/*
140 * generalized index_ interface routines (in indexam.c)
141 */
142
143extern Relation index_open(Oid relationId, LOCKMODE lockmode);
145extern void index_close(Relation relation, LOCKMODE lockmode);
146
147extern bool index_insert(Relation indexRelation,
148 Datum *values, bool *isnull,
150 Relation heapRelation,
152 bool indexUnchanged,
153 IndexInfo *indexInfo);
154extern void index_insert_cleanup(Relation indexRelation,
155 IndexInfo *indexInfo);
156
157extern IndexScanDesc index_beginscan(Relation heapRelation,
158 Relation indexRelation,
159 Snapshot snapshot,
160 IndexScanInstrumentation *instrument,
161 int nkeys, int norderbys);
163 Snapshot snapshot,
164 IndexScanInstrumentation *instrument,
165 int nkeys);
166extern void index_rescan(IndexScanDesc scan,
167 ScanKey keys, int nkeys,
168 ScanKey orderbys, int norderbys);
169extern void index_endscan(IndexScanDesc scan);
170extern void index_markpos(IndexScanDesc scan);
171extern void index_restrpos(IndexScanDesc scan);
172extern Size index_parallelscan_estimate(Relation indexRelation,
173 int nkeys, int norderbys, Snapshot snapshot,
174 bool instrument, bool parallel_aware,
175 int nworkers);
176extern void index_parallelscan_initialize(Relation heapRelation,
177 Relation indexRelation, Snapshot snapshot,
178 bool instrument, bool parallel_aware,
179 int nworkers,
181 ParallelIndexScanDesc target);
182extern void index_parallelrescan(IndexScanDesc scan);
184 Relation indexrel,
185 IndexScanInstrumentation *instrument,
186 int nkeys, int norderbys,
189 ScanDirection direction);
190extern bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot);
191extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
192 TupleTableSlot *slot);
193extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
194
198 void *callback_state);
200 IndexBulkDeleteResult *istat);
201extern bool index_can_return(Relation indexRelation, int attno);
207 Oid *orderByTypes,
208 IndexOrderByDistance *distances,
209 bool recheckOrderBy);
211 Datum attoptions, bool validate);
212
213
214/*
215 * index access method support routines (in genam.c)
216 */
217extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
218 int nkeys, int norderbys);
219extern void IndexScanEnd(IndexScanDesc scan);
220extern char *BuildIndexValueDescription(Relation indexRelation,
221 const Datum *values, const bool *isnull);
224 Buffer ibuf,
226 int nitems);
227
228/*
229 * heap-or-index access to system catalogs (in genam.c)
230 */
231extern SysScanDesc systable_beginscan(Relation heapRelation,
232 Oid indexId,
233 bool indexOK,
234 Snapshot snapshot,
235 int nkeys, ScanKey key);
240 Relation indexRelation,
241 Snapshot snapshot,
242 int nkeys, ScanKey key);
244 ScanDirection direction);
246extern void systable_inplace_update_begin(Relation relation,
247 Oid indexId,
248 bool indexOK,
249 Snapshot snapshot,
250 int nkeys, const ScanKeyData *key,
252 void **state);
253extern void systable_inplace_update_finish(void *state, HeapTuple tuple);
254extern void systable_inplace_update_cancel(void *state);
255
256#endif /* GENAM_H */
int16 AttrNumber
Definition attnum.h:21
static bool validate(Port *port, const char *auth)
Definition auth-oauth.c:638
uint32 BlockNumber
Definition block.h:31
static Datum values[MAXATTR]
Definition bootstrap.c:188
int Buffer
Definition buf.h:23
int64_t int64
Definition c.h:615
regproc RegProcedure
Definition c.h:736
uint16_t uint16
Definition c.h:617
uint32 TransactionId
Definition c.h:738
size_t Size
Definition c.h:691
char * BuildIndexValueDescription(Relation indexRelation, const Datum *values, const bool *isnull)
Definition genam.c:178
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:603
void systable_inplace_update_cancel(void *state)
Definition genam.c:903
void index_parallelscan_initialize(Relation heapRelation, Relation indexRelation, Snapshot snapshot, bool instrument, bool parallel_aware, int nworkers, SharedIndexScanInstrumentation **sharedinfo, ParallelIndexScanDesc target)
Definition indexam.c:520
bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition indexam.c:730
struct RelationData * Relation
Definition genam.h:30
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
Definition genam.c:573
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition genam.h:95
void IndexScanEnd(IndexScanDesc scan)
Definition genam.c:145
IndexUniqueCheck
Definition genam.h:124
@ UNIQUE_CHECK_NO
Definition genam.h:125
@ UNIQUE_CHECK_EXISTING
Definition genam.h:128
@ UNIQUE_CHECK_PARTIAL
Definition genam.h:127
@ UNIQUE_CHECK_YES
Definition genam.h:126
bool index_insert(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Definition indexam.c:213
IndexScanDesc index_beginscan_parallel(Relation heaprel, Relation indexrel, IndexScanInstrumentation *instrument, int nkeys, int norderbys, ParallelIndexScanDesc pscan)
Definition indexam.c:593
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition indexam.c:917
void index_restrpos(IndexScanDesc scan)
Definition indexam.c:446
IndexBulkDeleteResult * index_vacuum_cleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *istat)
Definition indexam.c:826
bytea * index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions, bool validate)
Definition indexam.c:1048
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, IndexScanInstrumentation *instrument, int nkeys, int norderbys)
Definition indexam.c:256
IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *istat, IndexBulkDeleteCallback callback, void *callback_state)
Definition indexam.c:805
void index_insert_cleanup(Relation indexRelation, IndexInfo *indexInfo)
Definition indexam.c:241
void systable_inplace_update_begin(Relation relation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, const ScanKeyData *key, HeapTuple *oldtupcopy, void **state)
Definition genam.c:808
TransactionId index_compute_xid_horizon_for_tuples(Relation irel, Relation hrel, Buffer ibuf, OffsetNumber *itemnos, int nitems)
Definition genam.c:295
void index_close(Relation relation, LOCKMODE lockmode)
Definition indexam.c:177
bool index_can_return(Relation indexRelation, int attno)
Definition indexam.c:845
ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction)
Definition indexam.c:631
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:650
void systable_inplace_update_finish(void *state, HeapTuple tuple)
Definition genam.c:884
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:514
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition indexam.c:883
bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot)
Definition indexam.c:689
void systable_endscan_ordered(SysScanDesc sysscan)
Definition genam.c:757
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
Definition genam.c:732
void index_markpos(IndexScanDesc scan)
Definition indexam.c:422
Relation try_index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:152
void index_endscan(IndexScanDesc scan)
Definition indexam.c:392
IndexScanDesc index_beginscan_bitmap(Relation indexRelation, Snapshot snapshot, IndexScanInstrumentation *instrument, int nkeys)
Definition indexam.c:299
Size index_parallelscan_estimate(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot, bool instrument, bool parallel_aware, int nworkers)
Definition indexam.c:471
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:133
struct SysScanDescData * SysScanDesc
Definition genam.h:99
int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap)
Definition indexam.c:775
void index_parallelrescan(IndexScanDesc scan)
Definition indexam.c:575
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition indexam.c:366
struct ParallelIndexScanDescData * ParallelIndexScanDesc
Definition genam.h:101
struct IndexScanDescData * IndexScanDesc
Definition genam.h:98
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition genam.c:80
void index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes, IndexOrderByDistance *distances, bool recheckOrderBy)
Definition indexam.c:985
#define nitems(x)
Definition indent.h:31
int LOCKMODE
Definition lockdefs.h:26
uint16 OffsetNumber
Definition off.h:24
int16 attnum
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
ScanDirection
Definition sdir.h:25
double heap_tuples
Definition genam.h:40
double index_tuples
Definition genam.h:41
BlockNumber pages_deleted
Definition genam.h:90
BlockNumber pages_newly_deleted
Definition genam.h:89
BlockNumber pages_free
Definition genam.h:91
BlockNumber num_pages
Definition genam.h:85
double tuples_removed
Definition genam.h:88
double num_index_tuples
Definition genam.h:87
Relation index
Definition genam.h:54
double num_heap_tuples
Definition genam.h:60
bool analyze_only
Definition genam.h:56
BufferAccessStrategy strategy
Definition genam.h:61
Relation heaprel
Definition genam.h:55
bool report_progress
Definition genam.h:57
int message_level
Definition genam.h:59
bool estimated_count
Definition genam.h:58
Definition c.h:778
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)