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.60 2006/05/10 23:18:39 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "access/itup.h"
18 #include "access/relscan.h"
19 #include "access/sdir.h"
20 #include "nodes/primnodes.h"
24 * Struct for statistics returned by ambuild
26 typedef struct IndexBuildResult
28 double heap_tuples; /* # of tuples seen in parent table */
29 double index_tuples; /* # of tuples inserted into index */
33 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
35 * Note that num_heap_tuples will not be valid during ambulkdelete,
36 * only amvacuumcleanup.
38 typedef struct IndexVacuumInfo
40 Relation index; /* the index being vacuumed */
41 bool vacuum_full; /* VACUUM FULL (we have exclusive lock) */
42 int message_level; /* ereport level for progress messages */
43 double num_heap_tuples; /* tuples remaining in heap */
47 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
49 * This struct is normally allocated by the first ambulkdelete call and then
50 * passed along through subsequent ones until amvacuumcleanup; however,
51 * amvacuumcleanup must be prepared to allocate it in the case where no
52 * ambulkdelete calls were made (because no tuples needed deletion).
53 * Note that an index AM could choose to return a larger struct
54 * of which this is just the first field; this provides a way for ambulkdelete
55 * to communicate additional private data to amvacuumcleanup.
57 * Note: pages_removed is the amount by which the index physically shrank,
58 * if any (ie the change in its total size on disk). pages_deleted and
59 * pages_free refer to free space within the index file.
61 typedef struct IndexBulkDeleteResult
63 BlockNumber num_pages; /* pages remaining in index */
64 BlockNumber pages_removed; /* # removed during vacuum operation */
65 double num_index_tuples; /* tuples remaining */
66 double tuples_removed; /* # removed during vacuum operation */
67 BlockNumber pages_deleted; /* # unused pages in index */
68 BlockNumber pages_free; /* # pages available for reuse */
69 } IndexBulkDeleteResult;
71 /* Typedef for callback function to determine if a tuple is bulk-deletable */
72 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
74 /* Struct for heap-or-index scans of system tables */
75 typedef struct SysScanDescData
77 Relation heap_rel; /* catalog being scanned */
78 Relation irel; /* NULL if doing heap scan */
79 HeapScanDesc scan; /* only valid in heap-scan case */
80 IndexScanDesc iscan; /* only valid in index-scan case */
83 typedef SysScanDescData *SysScanDesc;
87 * generalized index_ interface routines (in indexam.c)
89 extern Relation index_open(Oid relationId);
90 extern Relation index_openrv(const RangeVar *relation);
91 extern void index_close(Relation relation);
92 extern bool index_insert(Relation indexRelation,
93 Datum *values, bool *isnull,
94 ItemPointer heap_t_ctid,
95 Relation heapRelation,
96 bool check_uniqueness);
98 extern IndexScanDesc index_beginscan(Relation heapRelation,
99 Relation indexRelation,
100 bool need_index_lock,
102 int nkeys, ScanKey key);
103 extern IndexScanDesc index_beginscan_multi(Relation indexRelation,
104 bool need_index_lock,
106 int nkeys, ScanKey key);
107 extern void index_rescan(IndexScanDesc scan, ScanKey key);
108 extern void index_endscan(IndexScanDesc scan);
109 extern void index_markpos(IndexScanDesc scan);
110 extern void index_restrpos(IndexScanDesc scan);
111 extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
112 extern bool index_getnext_indexitem(IndexScanDesc scan,
113 ScanDirection direction);
114 extern bool index_getmulti(IndexScanDesc scan,
115 ItemPointer tids, int32 max_tids,
116 int32 *returned_tids);
118 extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
119 IndexBulkDeleteResult *stats,
120 IndexBulkDeleteCallback callback,
121 void *callback_state);
122 extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
123 IndexBulkDeleteResult *stats);
124 extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
126 extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
130 * index access method support routines (in genam.c)
132 extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
133 int nkeys, ScanKey key);
134 extern void IndexScanEnd(IndexScanDesc scan);
137 * heap-or-index access to system catalogs (in genam.c)
139 extern SysScanDesc systable_beginscan(Relation heapRelation,
143 int nkeys, ScanKey key);
144 extern HeapTuple systable_getnext(SysScanDesc sysscan);
145 extern void systable_endscan(SysScanDesc sysscan);