1 /*-------------------------------------------------------------------------
4 * POSTGRES generalized index access method definitions.
7 * Portions Copyright (c) 1996-2008, 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 * Note that num_heap_tuples will not be valid during ambulkdelete,
38 * only amvacuumcleanup.
40 typedef struct IndexVacuumInfo
42 Relation index
; /* the index being vacuumed */
43 bool vacuum_full
; /* VACUUM FULL (we have exclusive lock) */
44 int message_level
; /* ereport level for progress messages */
45 double num_heap_tuples
; /* tuples remaining in heap */
46 BufferAccessStrategy strategy
; /* access strategy for reads */
50 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
52 * This struct is normally allocated by the first ambulkdelete call and then
53 * passed along through subsequent ones until amvacuumcleanup; however,
54 * amvacuumcleanup must be prepared to allocate it in the case where no
55 * ambulkdelete calls were made (because no tuples needed deletion).
56 * Note that an index AM could choose to return a larger struct
57 * of which this is just the first field; this provides a way for ambulkdelete
58 * to communicate additional private data to amvacuumcleanup.
60 * Note: pages_removed is the amount by which the index physically shrank,
61 * if any (ie the change in its total size on disk). pages_deleted and
62 * pages_free refer to free space within the index file.
64 typedef struct IndexBulkDeleteResult
66 BlockNumber num_pages
; /* pages remaining in index */
67 BlockNumber pages_removed
; /* # removed during vacuum operation */
68 double num_index_tuples
; /* tuples remaining */
69 double tuples_removed
; /* # removed during vacuum operation */
70 BlockNumber pages_deleted
; /* # unused pages in index */
71 BlockNumber pages_free
; /* # pages available for reuse */
72 } IndexBulkDeleteResult
;
74 /* Typedef for callback function to determine if a tuple is bulk-deletable */
75 typedef bool (*IndexBulkDeleteCallback
) (ItemPointer itemptr
, void *state
);
77 /* struct definitions appear in relscan.h */
78 typedef struct IndexScanDescData
*IndexScanDesc
;
79 typedef struct SysScanDescData
*SysScanDesc
;
83 * generalized index_ interface routines (in indexam.c)
88 * True iff the index scan is valid.
90 #define IndexScanIsValid(scan) PointerIsValid(scan)
92 extern Relation
index_open(Oid relationId
, LOCKMODE lockmode
);
93 extern void index_close(Relation relation
, LOCKMODE lockmode
);
95 extern bool index_insert(Relation indexRelation
,
96 Datum
*values
, bool *isnull
,
97 ItemPointer heap_t_ctid
,
98 Relation heapRelation
,
99 bool check_uniqueness
);
101 extern IndexScanDesc
index_beginscan(Relation heapRelation
,
102 Relation indexRelation
,
104 int nkeys
, ScanKey key
);
105 extern IndexScanDesc
index_beginscan_bitmap(Relation indexRelation
,
107 int nkeys
, ScanKey key
);
108 extern void index_rescan(IndexScanDesc scan
, ScanKey key
);
109 extern void index_endscan(IndexScanDesc scan
);
110 extern void index_markpos(IndexScanDesc scan
);
111 extern void index_restrpos(IndexScanDesc scan
);
112 extern HeapTuple
index_getnext(IndexScanDesc scan
, ScanDirection direction
);
113 extern int64
index_getbitmap(IndexScanDesc scan
, TIDBitmap
*bitmap
);
115 extern IndexBulkDeleteResult
*index_bulk_delete(IndexVacuumInfo
*info
,
116 IndexBulkDeleteResult
*stats
,
117 IndexBulkDeleteCallback callback
,
118 void *callback_state
);
119 extern IndexBulkDeleteResult
*index_vacuum_cleanup(IndexVacuumInfo
*info
,
120 IndexBulkDeleteResult
*stats
);
121 extern RegProcedure
index_getprocid(Relation irel
, AttrNumber attnum
,
123 extern FmgrInfo
*index_getprocinfo(Relation irel
, AttrNumber attnum
,
127 * index access method support routines (in genam.c)
129 extern IndexScanDesc
RelationGetIndexScan(Relation indexRelation
,
130 int nkeys
, ScanKey key
);
131 extern void IndexScanEnd(IndexScanDesc scan
);
134 * heap-or-index access to system catalogs (in genam.c)
136 extern SysScanDesc
systable_beginscan(Relation heapRelation
,
140 int nkeys
, ScanKey key
);
141 extern HeapTuple
systable_getnext(SysScanDesc sysscan
);
142 extern bool systable_recheck_tuple(SysScanDesc sysscan
, HeapTuple tup
);
143 extern void systable_endscan(SysScanDesc sysscan
);
144 extern SysScanDesc
systable_beginscan_ordered(Relation heapRelation
,
145 Relation indexRelation
,
147 int nkeys
, ScanKey key
);
148 extern HeapTuple
systable_getnext_ordered(SysScanDesc sysscan
,
149 ScanDirection direction
);
150 extern void systable_endscan_ordered(SysScanDesc sysscan
);