1 /*-------------------------------------------------------------------------
4 * POSTGRES generalized index access method definitions.
7 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/access/genam.h,v 1.65 2006/07/31 20:09:05 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "access/relscan.h"
18 #include "access/sdir.h"
19 #include "nodes/primnodes.h"
20 #include "storage/lock.h"
23 * Struct for statistics returned by ambuild
25 typedef struct IndexBuildResult
27 double heap_tuples; /* # of tuples seen in parent table */
28 double index_tuples; /* # of tuples inserted into index */
32 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
34 * Note that num_heap_tuples will not be valid during ambulkdelete,
35 * only amvacuumcleanup.
37 typedef struct IndexVacuumInfo
39 Relation index; /* the index being vacuumed */
40 bool vacuum_full; /* VACUUM FULL (we have exclusive lock) */
41 int message_level; /* ereport level for progress messages */
42 double num_heap_tuples; /* tuples remaining in heap */
46 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
48 * This struct is normally allocated by the first ambulkdelete call and then
49 * passed along through subsequent ones until amvacuumcleanup; however,
50 * amvacuumcleanup must be prepared to allocate it in the case where no
51 * ambulkdelete calls were made (because no tuples needed deletion).
52 * Note that an index AM could choose to return a larger struct
53 * of which this is just the first field; this provides a way for ambulkdelete
54 * to communicate additional private data to amvacuumcleanup.
56 * Note: pages_removed is the amount by which the index physically shrank,
57 * if any (ie the change in its total size on disk). pages_deleted and
58 * pages_free refer to free space within the index file.
60 typedef struct IndexBulkDeleteResult
62 BlockNumber num_pages; /* pages remaining in index */
63 BlockNumber pages_removed; /* # removed during vacuum operation */
64 double num_index_tuples; /* tuples remaining */
65 double tuples_removed; /* # removed during vacuum operation */
66 BlockNumber pages_deleted; /* # unused pages in index */
67 BlockNumber pages_free; /* # pages available for reuse */
68 } IndexBulkDeleteResult;
70 /* Typedef for callback function to determine if a tuple is bulk-deletable */
71 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
73 /* Struct for heap-or-index scans of system tables */
74 typedef struct SysScanDescData
76 Relation heap_rel; /* catalog being scanned */
77 Relation irel; /* NULL if doing heap scan */
78 HeapScanDesc scan; /* only valid in heap-scan case */
79 IndexScanDesc iscan; /* only valid in index-scan case */
82 typedef SysScanDescData *SysScanDesc;
86 * generalized index_ interface routines (in indexam.c)
88 extern Relation index_open(Oid relationId, LOCKMODE lockmode);
89 extern void index_close(Relation relation, LOCKMODE lockmode);
91 extern bool index_insert(Relation indexRelation,
92 Datum *values, bool *isnull,
93 ItemPointer heap_t_ctid,
94 Relation heapRelation,
95 bool check_uniqueness);
97 extern IndexScanDesc index_beginscan(Relation heapRelation,
98 Relation indexRelation,
100 int nkeys, ScanKey key);
101 extern IndexScanDesc index_beginscan_multi(Relation indexRelation,
103 int nkeys, ScanKey key);
104 extern void index_rescan(IndexScanDesc scan, ScanKey key);
105 extern void index_endscan(IndexScanDesc scan);
106 extern void index_markpos(IndexScanDesc scan);
107 extern void index_restrpos(IndexScanDesc scan);
108 extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
109 extern bool index_getnext_indexitem(IndexScanDesc scan,
110 ScanDirection direction);
111 extern bool index_getmulti(IndexScanDesc scan,
112 ItemPointer tids, int32 max_tids,
113 int32 *returned_tids);
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 void systable_endscan(SysScanDesc sysscan);