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 "nodes/tidbitmap.h"
22#include "storage/buf.h"
23#include "storage/lockdefs.h"
24#include "utils/snapshot.h"
25
26/* We don't want this file to depend on execnodes.h. */
27typedef struct IndexInfo IndexInfo;
29
30/* or relcache.h */
31typedef struct RelationData *Relation;
32
33/*
34 * Struct for statistics returned by ambuild
35 */
36typedef struct IndexBuildResult
37{
38 double heap_tuples; /* # of tuples seen in parent table */
39 double index_tuples; /* # of tuples inserted into index */
41
42/*
43 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
44 *
45 * num_heap_tuples is accurate only when estimated_count is false;
46 * otherwise it's just an estimate (currently, the estimate is the
47 * prior value of the relation's pg_class.reltuples field, so it could
48 * even be -1). It will always just be an estimate during ambulkdelete.
49 */
50typedef struct IndexVacuumInfo
51{
52 Relation index; /* the index being vacuumed */
53 Relation heaprel; /* the heap relation the index belongs to */
54 bool analyze_only; /* ANALYZE (without any actual vacuum) */
55 bool report_progress; /* emit progress.h status reports */
56 bool estimated_count; /* num_heap_tuples is an estimate */
57 int message_level; /* ereport level for progress messages */
58 double num_heap_tuples; /* tuples remaining in heap */
59 BufferAccessStrategy strategy; /* access strategy for reads */
61
62/*
63 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
64 *
65 * This struct is normally allocated by the first ambulkdelete call and then
66 * passed along through subsequent ones until amvacuumcleanup; however,
67 * amvacuumcleanup must be prepared to allocate it in the case where no
68 * ambulkdelete calls were made (because no tuples needed deletion).
69 * Note that an index AM could choose to return a larger struct
70 * of which this is just the first field; this provides a way for ambulkdelete
71 * to communicate additional private data to amvacuumcleanup.
72 *
73 * Note: pages_newly_deleted is the number of pages in the index that were
74 * deleted by the current vacuum operation. pages_deleted and pages_free
75 * refer to free space within the index file.
76 *
77 * Note: Some index AMs may compute num_index_tuples by reference to
78 * num_heap_tuples, in which case they should copy the estimated_count field
79 * from IndexVacuumInfo.
80 */
82{
83 BlockNumber num_pages; /* pages remaining in index */
84 bool estimated_count; /* num_index_tuples is an estimate */
85 double num_index_tuples; /* tuples remaining */
86 double tuples_removed; /* # removed during vacuum operation */
87 BlockNumber pages_newly_deleted; /* # pages marked deleted by us */
88 BlockNumber pages_deleted; /* # pages marked deleted (could be by us) */
89 BlockNumber pages_free; /* # pages available for reuse */
91
92/* Typedef for callback function to determine if a tuple is bulk-deletable */
93typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
94
95/* struct definitions appear in relscan.h */
98
100
101/*
102 * Enumeration specifying the type of uniqueness check to perform in
103 * index_insert().
104 *
105 * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
106 * blocking to see if a conflicting transaction commits.
107 *
108 * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
109 * insertion time. The index AM should test if the tuple is unique, but
110 * should not throw error, block, or prevent the insertion if the tuple
111 * appears not to be unique. We'll recheck later when it is time for the
112 * constraint to be enforced. The AM must return true if the tuple is
113 * known unique, false if it is possibly non-unique. In the "true" case
114 * it is safe to omit the later recheck.
115 *
116 * When it is time to recheck the deferred constraint, a pseudo-insertion
117 * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
118 * index in this case, so it should not be inserted again. Rather, just
119 * check for conflicting live tuples (possibly blocking).
120 */
122{
123 UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
124 UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
125 UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
126 UNIQUE_CHECK_EXISTING, /* Check if existing tuple is unique */
128
129
130/* Nullable "ORDER BY col op const" distance */
136
137/*
138 * generalized index_ interface routines (in indexam.c)
139 */
140
141extern Relation index_open(Oid relationId, LOCKMODE lockmode);
143extern void index_close(Relation relation, LOCKMODE lockmode);
144
145extern bool index_insert(Relation indexRelation,
146 Datum *values, bool *isnull,
148 Relation heapRelation,
150 bool indexUnchanged,
151 IndexInfo *indexInfo);
152extern void index_insert_cleanup(Relation indexRelation,
153 IndexInfo *indexInfo);
154
155extern IndexScanDesc index_beginscan(Relation heapRelation,
156 Relation indexRelation,
157 Snapshot snapshot,
158 IndexScanInstrumentation *instrument,
159 int nkeys, int norderbys);
161 Snapshot snapshot,
162 IndexScanInstrumentation *instrument,
163 int nkeys);
164extern void index_rescan(IndexScanDesc scan,
165 ScanKey keys, int nkeys,
166 ScanKey orderbys, int norderbys);
167extern void index_endscan(IndexScanDesc scan);
168extern void index_markpos(IndexScanDesc scan);
169extern void index_restrpos(IndexScanDesc scan);
170extern Size index_parallelscan_estimate(Relation indexRelation,
171 int nkeys, int norderbys, Snapshot snapshot,
172 bool instrument, bool parallel_aware,
173 int nworkers);
174extern void index_parallelscan_initialize(Relation heapRelation,
175 Relation indexRelation, Snapshot snapshot,
176 bool instrument, bool parallel_aware,
177 int nworkers,
179 ParallelIndexScanDesc target);
180extern void index_parallelrescan(IndexScanDesc scan);
182 Relation indexrel,
183 IndexScanInstrumentation *instrument,
184 int nkeys, int norderbys,
187 ScanDirection direction);
188extern bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot);
189extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
190 TupleTableSlot *slot);
191extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
192
196 void *callback_state);
198 IndexBulkDeleteResult *istat);
199extern bool index_can_return(Relation indexRelation, int attno);
205 Oid *orderByTypes,
206 IndexOrderByDistance *distances,
207 bool recheckOrderBy);
209 Datum attoptions, bool validate);
210
211
212/*
213 * index access method support routines (in genam.c)
214 */
215extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
216 int nkeys, int norderbys);
217extern void IndexScanEnd(IndexScanDesc scan);
218extern char *BuildIndexValueDescription(Relation indexRelation,
219 const Datum *values, const bool *isnull);
222 Buffer ibuf,
224 int nitems);
225
226/*
227 * heap-or-index access to system catalogs (in genam.c)
228 */
229extern SysScanDesc systable_beginscan(Relation heapRelation,
230 Oid indexId,
231 bool indexOK,
232 Snapshot snapshot,
233 int nkeys, ScanKey key);
238 Relation indexRelation,
239 Snapshot snapshot,
240 int nkeys, ScanKey key);
242 ScanDirection direction);
244extern void systable_inplace_update_begin(Relation relation,
245 Oid indexId,
246 bool indexOK,
247 Snapshot snapshot,
248 int nkeys, const ScanKeyData *key,
250 void **state);
251extern void systable_inplace_update_finish(void *state, HeapTuple tuple);
252extern void systable_inplace_update_cancel(void *state);
253
254#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:155
int Buffer
Definition buf.h:23
int64_t int64
Definition c.h:543
regproc RegProcedure
Definition c.h:664
uint16_t uint16
Definition c.h:545
uint32 TransactionId
Definition c.h:666
size_t Size
Definition c.h:619
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:31
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
Definition genam.c:573
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition genam.h:93
void IndexScanEnd(IndexScanDesc scan)
Definition genam.c:145
IndexUniqueCheck
Definition genam.h:122
@ UNIQUE_CHECK_NO
Definition genam.h:123
@ UNIQUE_CHECK_EXISTING
Definition genam.h:126
@ UNIQUE_CHECK_PARTIAL
Definition genam.h:125
@ UNIQUE_CHECK_YES
Definition genam.h:124
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:97
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:99
struct IndexScanDescData * IndexScanDesc
Definition genam.h:96
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:38
double index_tuples
Definition genam.h:39
BlockNumber pages_deleted
Definition genam.h:88
BlockNumber pages_newly_deleted
Definition genam.h:87
BlockNumber pages_free
Definition genam.h:89
BlockNumber num_pages
Definition genam.h:83
double tuples_removed
Definition genam.h:86
double num_index_tuples
Definition genam.h:85
Relation index
Definition genam.h:52
double num_heap_tuples
Definition genam.h:58
bool analyze_only
Definition genam.h:54
BufferAccessStrategy strategy
Definition genam.h:59
Relation heaprel
Definition genam.h:53
bool report_progress
Definition genam.h:55
int message_level
Definition genam.h:57
bool estimated_count
Definition genam.h:56
Definition c.h:706
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)