Pass down "logically unchanged index" hint.
[pgsql.git] / src / include / access / genam.h
blob0eab1508d37538eb940a0926de6f2a7a54bef874
1 /*-------------------------------------------------------------------------
3 * genam.h
4 * POSTGRES generalized index access method definitions.
7 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/access/genam.h
12 *-------------------------------------------------------------------------
14 #ifndef GENAM_H
15 #define GENAM_H
17 #include "access/sdir.h"
18 #include "access/skey.h"
19 #include "nodes/tidbitmap.h"
20 #include "storage/lockdefs.h"
21 #include "utils/relcache.h"
22 #include "utils/snapshot.h"
24 /* We don't want this file to depend on execnodes.h. */
25 struct IndexInfo;
28 * Struct for statistics returned by ambuild
30 typedef struct IndexBuildResult
32 double heap_tuples; /* # of tuples seen in parent table */
33 double index_tuples; /* # of tuples inserted into index */
34 } IndexBuildResult;
37 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
39 * num_heap_tuples is accurate only when estimated_count is false;
40 * otherwise it's just an estimate (currently, the estimate is the
41 * prior value of the relation's pg_class.reltuples field, so it could
42 * even be -1). It will always just be an estimate during ambulkdelete.
44 typedef struct IndexVacuumInfo
46 Relation index; /* the index being vacuumed */
47 bool analyze_only; /* ANALYZE (without any actual vacuum) */
48 bool report_progress; /* emit progress.h status reports */
49 bool estimated_count; /* num_heap_tuples is an estimate */
50 int message_level; /* ereport level for progress messages */
51 double num_heap_tuples; /* tuples remaining in heap */
52 BufferAccessStrategy strategy; /* access strategy for reads */
53 } IndexVacuumInfo;
56 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
58 * This struct is normally allocated by the first ambulkdelete call and then
59 * passed along through subsequent ones until amvacuumcleanup; however,
60 * amvacuumcleanup must be prepared to allocate it in the case where no
61 * ambulkdelete calls were made (because no tuples needed deletion).
62 * Note that an index AM could choose to return a larger struct
63 * of which this is just the first field; this provides a way for ambulkdelete
64 * to communicate additional private data to amvacuumcleanup.
66 * Note: pages_removed is the amount by which the index physically shrank,
67 * if any (ie the change in its total size on disk). pages_deleted and
68 * pages_free refer to free space within the index file. Some index AMs
69 * may compute num_index_tuples by reference to num_heap_tuples, in which
70 * case they should copy the estimated_count field from IndexVacuumInfo.
72 typedef struct IndexBulkDeleteResult
74 BlockNumber num_pages; /* pages remaining in index */
75 BlockNumber pages_removed; /* # removed during vacuum operation */
76 bool estimated_count; /* num_index_tuples is an estimate */
77 double num_index_tuples; /* tuples remaining */
78 double tuples_removed; /* # removed during vacuum operation */
79 BlockNumber pages_deleted; /* # unused pages in index */
80 BlockNumber pages_free; /* # pages available for reuse */
81 } IndexBulkDeleteResult;
83 /* Typedef for callback function to determine if a tuple is bulk-deletable */
84 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
86 /* struct definitions appear in relscan.h */
87 typedef struct IndexScanDescData *IndexScanDesc;
88 typedef struct SysScanDescData *SysScanDesc;
90 typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
93 * Enumeration specifying the type of uniqueness check to perform in
94 * index_insert().
96 * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
97 * blocking to see if a conflicting transaction commits.
99 * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
100 * insertion time. The index AM should test if the tuple is unique, but
101 * should not throw error, block, or prevent the insertion if the tuple
102 * appears not to be unique. We'll recheck later when it is time for the
103 * constraint to be enforced. The AM must return true if the tuple is
104 * known unique, false if it is possibly non-unique. In the "true" case
105 * it is safe to omit the later recheck.
107 * When it is time to recheck the deferred constraint, a pseudo-insertion
108 * call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
109 * index in this case, so it should not be inserted again. Rather, just
110 * check for conflicting live tuples (possibly blocking).
112 typedef enum IndexUniqueCheck
114 UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
115 UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
116 UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
117 UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
118 } IndexUniqueCheck;
121 /* Nullable "ORDER BY col op const" distance */
122 typedef struct IndexOrderByDistance
124 double value;
125 bool isnull;
126 } IndexOrderByDistance;
129 * generalized index_ interface routines (in indexam.c)
133 * IndexScanIsValid
134 * True iff the index scan is valid.
136 #define IndexScanIsValid(scan) PointerIsValid(scan)
138 extern Relation index_open(Oid relationId, LOCKMODE lockmode);
139 extern void index_close(Relation relation, LOCKMODE lockmode);
141 extern bool index_insert(Relation indexRelation,
142 Datum *values, bool *isnull,
143 ItemPointer heap_t_ctid,
144 Relation heapRelation,
145 IndexUniqueCheck checkUnique,
146 bool indexUnchanged,
147 struct IndexInfo *indexInfo);
149 extern IndexScanDesc index_beginscan(Relation heapRelation,
150 Relation indexRelation,
151 Snapshot snapshot,
152 int nkeys, int norderbys);
153 extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
154 Snapshot snapshot,
155 int nkeys);
156 extern void index_rescan(IndexScanDesc scan,
157 ScanKey keys, int nkeys,
158 ScanKey orderbys, int norderbys);
159 extern void index_endscan(IndexScanDesc scan);
160 extern void index_markpos(IndexScanDesc scan);
161 extern void index_restrpos(IndexScanDesc scan);
162 extern Size index_parallelscan_estimate(Relation indexrel, Snapshot snapshot);
163 extern void index_parallelscan_initialize(Relation heaprel, Relation indexrel,
164 Snapshot snapshot, ParallelIndexScanDesc target);
165 extern void index_parallelrescan(IndexScanDesc scan);
166 extern IndexScanDesc index_beginscan_parallel(Relation heaprel,
167 Relation indexrel, int nkeys, int norderbys,
168 ParallelIndexScanDesc pscan);
169 extern ItemPointer index_getnext_tid(IndexScanDesc scan,
170 ScanDirection direction);
171 struct TupleTableSlot;
172 extern bool index_fetch_heap(IndexScanDesc scan, struct TupleTableSlot *slot);
173 extern bool index_getnext_slot(IndexScanDesc scan, ScanDirection direction,
174 struct TupleTableSlot *slot);
175 extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
177 extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
178 IndexBulkDeleteResult *stats,
179 IndexBulkDeleteCallback callback,
180 void *callback_state);
181 extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
182 IndexBulkDeleteResult *stats);
183 extern bool index_can_return(Relation indexRelation, int attno);
184 extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
185 uint16 procnum);
186 extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
187 uint16 procnum);
188 extern void index_store_float8_orderby_distances(IndexScanDesc scan,
189 Oid *orderByTypes,
190 IndexOrderByDistance *distances,
191 bool recheckOrderBy);
192 extern bytea *index_opclass_options(Relation relation, AttrNumber attnum,
193 Datum attoptions, bool validate);
197 * index access method support routines (in genam.c)
199 extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
200 int nkeys, int norderbys);
201 extern void IndexScanEnd(IndexScanDesc scan);
202 extern char *BuildIndexValueDescription(Relation indexRelation,
203 Datum *values, bool *isnull);
204 extern TransactionId index_compute_xid_horizon_for_tuples(Relation irel,
205 Relation hrel,
206 Buffer ibuf,
207 OffsetNumber *itemnos,
208 int nitems);
211 * heap-or-index access to system catalogs (in genam.c)
213 extern SysScanDesc systable_beginscan(Relation heapRelation,
214 Oid indexId,
215 bool indexOK,
216 Snapshot snapshot,
217 int nkeys, ScanKey key);
218 extern HeapTuple systable_getnext(SysScanDesc sysscan);
219 extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
220 extern void systable_endscan(SysScanDesc sysscan);
221 extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
222 Relation indexRelation,
223 Snapshot snapshot,
224 int nkeys, ScanKey key);
225 extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
226 ScanDirection direction);
227 extern void systable_endscan_ordered(SysScanDesc sysscan);
229 #endif /* GENAM_H */