Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
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-2025, 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"
20#include "nodes/tidbitmap.h"
21#include "storage/buf.h"
22#include "storage/lockdefs.h"
23#include "utils/snapshot.h"
24
25/* We don't want this file to depend on execnodes.h. */
26typedef struct IndexInfo IndexInfo;
28
29/* or relcache.h */
30typedef struct RelationData *Relation;
31
32
33/*
34 * Struct for statistics maintained by amgettuple and amgetbitmap
35 *
36 * Note: IndexScanInstrumentation can't contain any pointers, since it is
37 * copied into a SharedIndexScanInstrumentation during parallel scans
38 */
40{
41 /* Index search count (incremented with pgstat_count_index_scan call) */
44
45/*
46 * Struct for every worker's IndexScanInstrumentation, stored in shared memory
47 */
49{
53
54/*
55 * Struct for statistics returned by ambuild
56 */
57typedef struct IndexBuildResult
58{
59 double heap_tuples; /* # of tuples seen in parent table */
60 double index_tuples; /* # of tuples inserted into index */
62
63/*
64 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
65 *
66 * num_heap_tuples is accurate only when estimated_count is false;
67 * otherwise it's just an estimate (currently, the estimate is the
68 * prior value of the relation's pg_class.reltuples field, so it could
69 * even be -1). It will always just be an estimate during ambulkdelete.
70 */
71typedef struct IndexVacuumInfo
72{
73 Relation index; /* the index being vacuumed */
74 Relation heaprel; /* the heap relation the index belongs to */
75 bool analyze_only; /* ANALYZE (without any actual vacuum) */
76 bool report_progress; /* emit progress.h status reports */
77 bool estimated_count; /* num_heap_tuples is an estimate */
78 int message_level; /* ereport level for progress messages */
79 double num_heap_tuples; /* tuples remaining in heap */
80 BufferAccessStrategy strategy; /* access strategy for reads */
82
83/*
84 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
85 *
86 * This struct is normally allocated by the first ambulkdelete call and then
87 * passed along through subsequent ones until amvacuumcleanup; however,
88 * amvacuumcleanup must be prepared to allocate it in the case where no
89 * ambulkdelete calls were made (because no tuples needed deletion).
90 * Note that an index AM could choose to return a larger struct
91 * of which this is just the first field; this provides a way for ambulkdelete
92 * to communicate additional private data to amvacuumcleanup.
93 *
94 * Note: pages_newly_deleted is the number of pages in the index that were
95 * deleted by the current vacuum operation. pages_deleted and pages_free
96 * refer to free space within the index file.
97 *
98 * Note: Some index AMs may compute num_index_tuples by reference to
99 * num_heap_tuples, in which case they should copy the estimated_count field
100 * from IndexVacuumInfo.
101 */
103{
104 BlockNumber num_pages; /* pages remaining in index */
105 bool estimated_count; /* num_index_tuples is an estimate */
106 double num_index_tuples; /* tuples remaining */
107 double tuples_removed; /* # removed during vacuum operation */
108 BlockNumber pages_newly_deleted; /* # pages marked deleted by us */
109 BlockNumber pages_deleted; /* # pages marked deleted (could be by us) */
110 BlockNumber pages_free; /* # pages available for reuse */
112
113/* Typedef for callback function to determine if a tuple is bulk-deletable */
114typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
115
116/* struct definitions appear in relscan.h */
119
121
122/*
123 * Enumeration specifying the type of uniqueness check to perform in
124 * index_insert().
125 *
126 * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
127 * blocking to see if a conflicting transaction commits.
128 *
129 * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
130 * insertion time. The index AM should test if the tuple is unique, but
131 * should not throw error, block, or prevent the insertion if the tuple
132 * appears not to be unique. We'll recheck later when it is time for the
133 * constraint to be enforced. The AM must return true if the tuple is
134 * known unique, false if it is possibly non-unique. In the "true" case
135 * it is safe to omit the later recheck.
136 *
137 * When it is time to recheck the deferred constraint, a pseudo-insertion
138 * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
139 * index in this case, so it should not be inserted again. Rather, just
140 * check for conflicting live tuples (possibly blocking).
141 */
143{
144 UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
145 UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
146 UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
147 UNIQUE_CHECK_EXISTING, /* Check if existing tuple is unique */
149
150
151/* Nullable "ORDER BY col op const" distance */
153{
154 double value;
155 bool isnull;
157
158/*
159 * generalized index_ interface routines (in indexam.c)
160 */
161
162extern Relation index_open(Oid relationId, LOCKMODE lockmode);
163extern Relation try_index_open(Oid relationId, LOCKMODE lockmode);
164extern void index_close(Relation relation, LOCKMODE lockmode);
165
166extern bool index_insert(Relation indexRelation,
167 Datum *values, bool *isnull,
168 ItemPointer heap_t_ctid,
169 Relation heapRelation,
170 IndexUniqueCheck checkUnique,
171 bool indexUnchanged,
172 IndexInfo *indexInfo);
173extern void index_insert_cleanup(Relation indexRelation,
174 IndexInfo *indexInfo);
175
176extern IndexScanDesc index_beginscan(Relation heapRelation,
177 Relation indexRelation,
178 Snapshot snapshot,
179 IndexScanInstrumentation *instrument,
180 int nkeys, int norderbys);
182 Snapshot snapshot,
183 IndexScanInstrumentation *instrument,
184 int nkeys);
185extern void index_rescan(IndexScanDesc scan,
186 ScanKey keys, int nkeys,
187 ScanKey orderbys, int norderbys);
188extern void index_endscan(IndexScanDesc scan);
189extern void index_markpos(IndexScanDesc scan);
190extern void index_restrpos(IndexScanDesc scan);
191extern Size index_parallelscan_estimate(Relation indexRelation,
192 int nkeys, int norderbys, Snapshot snapshot,
193 bool instrument, bool parallel_aware,
194 int nworkers);
195extern void index_parallelscan_initialize(Relation heapRelation,
196 Relation indexRelation, Snapshot snapshot,
197 bool instrument, bool parallel_aware,
198 int nworkers,
200 ParallelIndexScanDesc target);
201extern void index_parallelrescan(IndexScanDesc scan);
203 Relation indexrel,
204 IndexScanInstrumentation *instrument,
205 int nkeys, int norderbys,
208 ScanDirection direction);
209extern bool index_fetch_heap(IndexScanDesc scan, TupleTableSlot *slot);
210extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
211 TupleTableSlot *slot);
212extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
213
217 void *callback_state);
219 IndexBulkDeleteResult *istat);
220extern bool index_can_return(Relation indexRelation, int attno);
222 uint16 procnum);
224 uint16 procnum);
226 Oid *orderByTypes,
227 IndexOrderByDistance *distances,
228 bool recheckOrderBy);
230 Datum attoptions, bool validate);
231
232
233/*
234 * index access method support routines (in genam.c)
235 */
236extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
237 int nkeys, int norderbys);
238extern void IndexScanEnd(IndexScanDesc scan);
239extern char *BuildIndexValueDescription(Relation indexRelation,
240 const Datum *values, const bool *isnull);
242 Relation hrel,
243 Buffer ibuf,
244 OffsetNumber *itemnos,
245 int nitems);
246
247/*
248 * heap-or-index access to system catalogs (in genam.c)
249 */
250extern SysScanDesc systable_beginscan(Relation heapRelation,
251 Oid indexId,
252 bool indexOK,
253 Snapshot snapshot,
254 int nkeys, ScanKey key);
256extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
257extern void systable_endscan(SysScanDesc sysscan);
259 Relation indexRelation,
260 Snapshot snapshot,
261 int nkeys, ScanKey key);
263 ScanDirection direction);
264extern void systable_endscan_ordered(SysScanDesc sysscan);
265extern void systable_inplace_update_begin(Relation relation,
266 Oid indexId,
267 bool indexOK,
268 Snapshot snapshot,
269 int nkeys, const ScanKeyData *key,
270 HeapTuple *oldtupcopy,
271 void **state);
272extern void systable_inplace_update_finish(void *state, HeapTuple tuple);
273extern void systable_inplace_update_cancel(void *state);
274
275#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:153
int Buffer
Definition: buf.h:23
int64_t int64
Definition: c.h:535
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:470
regproc RegProcedure
Definition: c.h:655
uint64_t uint64
Definition: c.h:539
uint16_t uint16
Definition: c.h:537
uint32 TransactionId
Definition: c.h:657
size_t Size
Definition: c.h:610
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:902
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
struct IndexOrderByDistance IndexOrderByDistance
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
Definition: genam.c:573
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition: genam.h:114
void IndexScanEnd(IndexScanDesc scan)
Definition: genam.c:145
IndexUniqueCheck
Definition: genam.h:143
@ UNIQUE_CHECK_NO
Definition: genam.h:144
@ UNIQUE_CHECK_EXISTING
Definition: genam.h:147
@ UNIQUE_CHECK_PARTIAL
Definition: genam.h:146
@ UNIQUE_CHECK_YES
Definition: genam.h:145
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
struct IndexVacuumInfo IndexVacuumInfo
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:807
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
struct IndexScanInstrumentation IndexScanInstrumentation
struct IndexBuildResult IndexBuildResult
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:883
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
struct IndexBulkDeleteResult IndexBulkDeleteResult
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:118
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:120
struct IndexScanDescData * IndexScanDesc
Definition: genam.h:117
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:388
struct SharedIndexScanInstrumentation SharedIndexScanInstrumentation
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
Definition: pg_attribute.h:74
uint64_t Datum
Definition: postgres.h:70
unsigned int Oid
Definition: postgres_ext.h:32
ScanDirection
Definition: sdir.h:25
Definition: fmgr.h:57
double heap_tuples
Definition: genam.h:59
double index_tuples
Definition: genam.h:60
BlockNumber pages_deleted
Definition: genam.h:109
BlockNumber pages_newly_deleted
Definition: genam.h:108
BlockNumber pages_free
Definition: genam.h:110
BlockNumber num_pages
Definition: genam.h:104
double tuples_removed
Definition: genam.h:107
double num_index_tuples
Definition: genam.h:106
Relation index
Definition: genam.h:73
double num_heap_tuples
Definition: genam.h:79
bool analyze_only
Definition: genam.h:75
BufferAccessStrategy strategy
Definition: genam.h:80
Relation heaprel
Definition: genam.h:74
bool report_progress
Definition: genam.h:76
int message_level
Definition: genam.h:78
bool estimated_count
Definition: genam.h:77
IndexScanInstrumentation winstrument[FLEXIBLE_ARRAY_MEMBER]
Definition: genam.h:51
Definition: regguts.h:323
Definition: c.h:692
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46