1 /*-------------------------------------------------------------------------
4 * POSTGRES generalized index access method definitions.
7 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 *-------------------------------------------------------------------------
17 #include "access/sdir.h"
18 #include "access/skey.h"
19 #include "nodes/tidbitmap.h"
20 #include "storage/buf.h"
21 #include "storage/lock.h"
22 #include "utils/relcache.h"
23 #include "utils/snapshot.h"
26 * Struct for statistics returned by ambuild
28 typedef struct IndexBuildResult
30 double heap_tuples
; /* # of tuples seen in parent table */
31 double index_tuples
; /* # of tuples inserted into index */
35 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
37 * num_heap_tuples is accurate only when estimated_count is false;
38 * otherwise it's just an estimate (currently, the estimate is the
39 * prior value of the relation's pg_class.reltuples field). It will
40 * always just be an estimate during ambulkdelete.
42 typedef struct IndexVacuumInfo
44 Relation index
; /* the index being vacuumed */
45 bool vacuum_full
; /* VACUUM FULL (we have exclusive lock) */
46 bool analyze_only
; /* ANALYZE (without any actual vacuum) */
47 bool estimated_count
; /* num_heap_tuples is an estimate */
48 int message_level
; /* ereport level for progress messages */
49 double num_heap_tuples
; /* tuples remaining in heap */
50 BufferAccessStrategy strategy
; /* access strategy for reads */
54 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
56 * This struct is normally allocated by the first ambulkdelete call and then
57 * passed along through subsequent ones until amvacuumcleanup; however,
58 * amvacuumcleanup must be prepared to allocate it in the case where no
59 * ambulkdelete calls were made (because no tuples needed deletion).
60 * Note that an index AM could choose to return a larger struct
61 * of which this is just the first field; this provides a way for ambulkdelete
62 * to communicate additional private data to amvacuumcleanup.
64 * Note: pages_removed is the amount by which the index physically shrank,
65 * if any (ie the change in its total size on disk). pages_deleted and
66 * pages_free refer to free space within the index file. Some index AMs
67 * may compute num_index_tuples by reference to num_heap_tuples, in which
68 * case they should copy the estimated_count field from IndexVacuumInfo.
70 typedef struct IndexBulkDeleteResult
72 BlockNumber num_pages
; /* pages remaining in index */
73 BlockNumber pages_removed
; /* # removed during vacuum operation */
74 bool estimated_count
; /* num_index_tuples is an estimate */
75 double num_index_tuples
; /* tuples remaining */
76 double tuples_removed
; /* # removed during vacuum operation */
77 BlockNumber pages_deleted
; /* # unused pages in index */
78 BlockNumber pages_free
; /* # pages available for reuse */
79 } IndexBulkDeleteResult
;
81 /* Typedef for callback function to determine if a tuple is bulk-deletable */
82 typedef bool (*IndexBulkDeleteCallback
) (ItemPointer itemptr
, void *state
);
84 /* struct definitions appear in relscan.h */
85 typedef struct IndexScanDescData
*IndexScanDesc
;
86 typedef struct SysScanDescData
*SysScanDesc
;
90 * generalized index_ interface routines (in indexam.c)
95 * True iff the index scan is valid.
97 #define IndexScanIsValid(scan) PointerIsValid(scan)
99 extern Relation
index_open(Oid relationId
, LOCKMODE lockmode
);
100 extern void index_close(Relation relation
, LOCKMODE lockmode
);
102 extern bool index_insert(Relation indexRelation
,
103 Datum
*values
, bool *isnull
,
104 ItemPointer heap_t_ctid
,
105 Relation heapRelation
,
106 bool check_uniqueness
);
108 extern IndexScanDesc
index_beginscan(Relation heapRelation
,
109 Relation indexRelation
,
111 int nkeys
, ScanKey key
);
112 extern IndexScanDesc
index_beginscan_bitmap(Relation indexRelation
,
114 int nkeys
, ScanKey key
);
115 extern void index_rescan(IndexScanDesc scan
, ScanKey key
);
116 extern void index_endscan(IndexScanDesc scan
);
117 extern void index_markpos(IndexScanDesc scan
);
118 extern void index_restrpos(IndexScanDesc scan
);
119 extern HeapTuple
index_getnext(IndexScanDesc scan
, ScanDirection direction
);
120 extern int64
index_getbitmap(IndexScanDesc scan
, TIDBitmap
*bitmap
);
122 extern IndexBulkDeleteResult
*index_bulk_delete(IndexVacuumInfo
*info
,
123 IndexBulkDeleteResult
*stats
,
124 IndexBulkDeleteCallback callback
,
125 void *callback_state
);
126 extern IndexBulkDeleteResult
*index_vacuum_cleanup(IndexVacuumInfo
*info
,
127 IndexBulkDeleteResult
*stats
);
128 extern RegProcedure
index_getprocid(Relation irel
, AttrNumber attnum
,
130 extern FmgrInfo
*index_getprocinfo(Relation irel
, AttrNumber attnum
,
134 * index access method support routines (in genam.c)
136 extern IndexScanDesc
RelationGetIndexScan(Relation indexRelation
,
137 int nkeys
, ScanKey key
);
138 extern void IndexScanEnd(IndexScanDesc scan
);
141 * heap-or-index access to system catalogs (in genam.c)
143 extern SysScanDesc
systable_beginscan(Relation heapRelation
,
147 int nkeys
, ScanKey key
);
148 extern HeapTuple
systable_getnext(SysScanDesc sysscan
);
149 extern bool systable_recheck_tuple(SysScanDesc sysscan
, HeapTuple tup
);
150 extern void systable_endscan(SysScanDesc sysscan
);
151 extern SysScanDesc
systable_beginscan_ordered(Relation heapRelation
,
152 Relation indexRelation
,
154 int nkeys
, ScanKey key
);
155 extern HeapTuple
systable_getnext_ordered(SysScanDesc sysscan
,
156 ScanDirection direction
);
157 extern void systable_endscan_ordered(SysScanDesc sysscan
);