]> granicus.if.org Git - postgresql/blob - src/include/access/genam.h
c1859a0c6d1ccc0fd6e245c848c3af36af116386
[postgresql] / src / include / access / genam.h
1 /*-------------------------------------------------------------------------
2  *
3  * genam.h
4  *        POSTGRES generalized index access method definitions.
5  *
6  *
7  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/access/genam.h,v 1.60 2006/05/10 23:18:39 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef GENAM_H
15 #define GENAM_H
16
17 #include "access/itup.h"
18 #include "access/relscan.h"
19 #include "access/sdir.h"
20 #include "nodes/primnodes.h"
21
22
23 /*
24  * Struct for statistics returned by ambuild
25  */
26 typedef struct IndexBuildResult
27 {
28         double          heap_tuples;    /* # of tuples seen in parent table */
29         double          index_tuples;   /* # of tuples inserted into index */
30 } IndexBuildResult;
31
32 /*
33  * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
34  *
35  * Note that num_heap_tuples will not be valid during ambulkdelete,
36  * only amvacuumcleanup.
37  */
38 typedef struct IndexVacuumInfo
39 {
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 */
44 } IndexVacuumInfo;
45
46 /*
47  * Struct for statistics returned by ambulkdelete and amvacuumcleanup
48  *
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.
56  *
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.
60  */
61 typedef struct IndexBulkDeleteResult
62 {
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;
70
71 /* Typedef for callback function to determine if a tuple is bulk-deletable */
72 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
73
74 /* Struct for heap-or-index scans of system tables */
75 typedef struct SysScanDescData
76 {
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 */
81 } SysScanDescData;
82
83 typedef SysScanDescData *SysScanDesc;
84
85
86 /*
87  * generalized index_ interface routines (in indexam.c)
88  */
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);
97
98 extern IndexScanDesc index_beginscan(Relation heapRelation,
99                                 Relation indexRelation,
100                                 bool need_index_lock,
101                                 Snapshot snapshot,
102                                 int nkeys, ScanKey key);
103 extern IndexScanDesc index_beginscan_multi(Relation indexRelation,
104                                           bool need_index_lock,
105                                           Snapshot snapshot,
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);
117
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,
125                                 uint16 procnum);
126 extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
127                                   uint16 procnum);
128
129 /*
130  * index access method support routines (in genam.c)
131  */
132 extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
133                                          int nkeys, ScanKey key);
134 extern void IndexScanEnd(IndexScanDesc scan);
135
136 /*
137  * heap-or-index access to system catalogs (in genam.c)
138  */
139 extern SysScanDesc systable_beginscan(Relation heapRelation,
140                                    Oid indexId,
141                                    bool indexOK,
142                                    Snapshot snapshot,
143                                    int nkeys, ScanKey key);
144 extern HeapTuple systable_getnext(SysScanDesc sysscan);
145 extern void systable_endscan(SysScanDesc sysscan);
146
147 #endif   /* GENAM_H */