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,
162 uint32 flags);
164 Snapshot snapshot,
165 IndexScanInstrumentation *instrument,
166 int nkeys);
167extern void index_rescan(IndexScanDesc scan,
168 ScanKey keys, int nkeys,
169 ScanKey orderbys, int norderbys);
170extern void index_endscan(IndexScanDesc scan);
171extern void index_markpos(IndexScanDesc scan);
172extern void index_restrpos(IndexScanDesc scan);
173extern Size index_parallelscan_estimate(Relation indexRelation,
174 int nkeys, int norderbys, Snapshot snapshot);
175extern void index_parallelscan_initialize(Relation heapRelation,
176 Relation indexRelation, Snapshot snapshot,
177 ParallelIndexScanDesc target);
178extern void index_parallelrescan(IndexScanDesc scan);
180 Relation indexrel,
181 IndexScanInstrumentation *instrument,
182 int nkeys, int norderbys,
184 uint32 flags);
186 ScanDirection direction);
187extern bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot);
188extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
189 TupleTableSlot *slot);
190extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
191
195 void *callback_state);
197 IndexBulkDeleteResult *istat);
198extern bool index_can_return(Relation indexRelation, int attno);
204 Oid *orderByTypes,
205 IndexOrderByDistance *distances,
206 bool recheckOrderBy);
208 Datum attoptions, bool validate);
209
210
211/*
212 * index access method support routines (in genam.c)
213 */
214extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
215 int nkeys, int norderbys);
216extern void IndexScanEnd(IndexScanDesc scan);
217extern char *BuildIndexValueDescription(Relation indexRelation,
218 const Datum *values, const bool *isnull);
221 Buffer ibuf,
223 int nitems);
224
225/*
226 * heap-or-index access to system catalogs (in genam.c)
227 */
228extern SysScanDesc systable_beginscan(Relation heapRelation,
229 Oid indexId,
230 bool indexOK,
231 Snapshot snapshot,
232 int nkeys, ScanKey key);
237 Relation indexRelation,
238 Snapshot snapshot,
239 int nkeys, ScanKey key);
241 ScanDirection direction);
243extern void systable_inplace_update_begin(Relation relation,
244 Oid indexId,
245 bool indexOK,
246 Snapshot snapshot,
247 int nkeys, const ScanKeyData *key,
249 void **state);
250extern void systable_inplace_update_finish(void *state, HeapTuple tuple);
251extern void systable_inplace_update_cancel(void *state);
252
253#endif /* GENAM_H */
int16 AttrNumber
Definition attnum.h:21
static bool validate(Port *port, const char *auth, const char **logdetail)
Definition auth-oauth.c:672
uint32 BlockNumber
Definition block.h:31
static Datum values[MAXATTR]
Definition bootstrap.c:190
int Buffer
Definition buf.h:23
int64_t int64
Definition c.h:621
regproc RegProcedure
Definition c.h:734
uint16_t uint16
Definition c.h:623
uint32_t uint32
Definition c.h:624
uint32 TransactionId
Definition c.h:736
size_t Size
Definition c.h:689
char * BuildIndexValueDescription(Relation indexRelation, const Datum *values, const bool *isnull)
Definition genam.c:178
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:612
void systable_inplace_update_cancel(void *state)
Definition genam.c:913
bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
Definition indexam.c:698
struct RelationData * Relation
Definition genam.h:30
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
Definition genam.c:582
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:214
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition indexam.c:885
void index_restrpos(IndexScanDesc scan)
Definition indexam.c:448
IndexBulkDeleteResult * index_vacuum_cleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *istat)
Definition indexam.c:794
bytea * index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions, bool validate)
Definition indexam.c:1016
IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *istat, IndexBulkDeleteCallback callback, void *callback_state)
Definition indexam.c:773
IndexScanDesc index_beginscan(Relation heapRelation, Relation indexRelation, Snapshot snapshot, IndexScanInstrumentation *instrument, int nkeys, int norderbys, uint32 flags)
Definition indexam.c:257
IndexScanDesc index_beginscan_parallel(Relation heaprel, Relation indexrel, IndexScanInstrumentation *instrument, int nkeys, int norderbys, ParallelIndexScanDesc pscan, uint32 flags)
Definition indexam.c:560
void index_insert_cleanup(Relation indexRelation, IndexInfo *indexInfo)
Definition indexam.c:242
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:818
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:178
bool index_can_return(Relation indexRelation, int attno)
Definition indexam.c:813
ItemPointer index_getnext_tid(IndexScanDesc scan, ScanDirection direction)
Definition indexam.c:599
SysScanDesc systable_beginscan_ordered(Relation heapRelation, Relation indexRelation, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:659
void systable_inplace_update_finish(void *state, HeapTuple tuple)
Definition genam.c:894
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:523
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
Definition indexam.c:851
bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot)
Definition indexam.c:657
void systable_endscan_ordered(SysScanDesc sysscan)
Definition genam.c:767
HeapTuple systable_getnext_ordered(SysScanDesc sysscan, ScanDirection direction)
Definition genam.c:742
void index_markpos(IndexScanDesc scan)
Definition indexam.c:424
Relation try_index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:153
void index_endscan(IndexScanDesc scan)
Definition indexam.c:394
Size index_parallelscan_estimate(Relation indexRelation, int nkeys, int norderbys, Snapshot snapshot)
Definition indexam.c:470
void index_parallelscan_initialize(Relation heapRelation, Relation indexRelation, Snapshot snapshot, ParallelIndexScanDesc target)
Definition indexam.c:505
IndexScanDesc index_beginscan_bitmap(Relation indexRelation, Snapshot snapshot, IndexScanInstrumentation *instrument, int nkeys)
Definition indexam.c:301
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition indexam.c:134
struct SysScanDescData * SysScanDesc
Definition genam.h:99
int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap)
Definition indexam.c:743
void index_parallelrescan(IndexScanDesc scan)
Definition indexam.c:538
void index_rescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int norderbys)
Definition indexam.c:368
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:953
#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:776
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)