]> granicus.if.org Git - postgresql/blob - src/include/access/genam.h
ddad1745279f03f04730c5f16751799aee14373a
[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.65 2006/07/31 20:09:05 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef GENAM_H
15 #define GENAM_H
16
17 #include "access/relscan.h"
18 #include "access/sdir.h"
19 #include "nodes/primnodes.h"
20 #include "storage/lock.h"
21
22 /*
23  * Struct for statistics returned by ambuild
24  */
25 typedef struct IndexBuildResult
26 {
27         double          heap_tuples;    /* # of tuples seen in parent table */
28         double          index_tuples;   /* # of tuples inserted into index */
29 } IndexBuildResult;
30
31 /*
32  * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
33  *
34  * Note that num_heap_tuples will not be valid during ambulkdelete,
35  * only amvacuumcleanup.
36  */
37 typedef struct IndexVacuumInfo
38 {
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 */
43 } IndexVacuumInfo;
44
45 /*
46  * Struct for statistics returned by ambulkdelete and amvacuumcleanup
47  *
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.
55  *
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.
59  */
60 typedef struct IndexBulkDeleteResult
61 {
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;
69
70 /* Typedef for callback function to determine if a tuple is bulk-deletable */
71 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
72
73 /* Struct for heap-or-index scans of system tables */
74 typedef struct SysScanDescData
75 {
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 */
80 } SysScanDescData;
81
82 typedef SysScanDescData *SysScanDesc;
83
84
85 /*
86  * generalized index_ interface routines (in indexam.c)
87  */
88 extern Relation index_open(Oid relationId, LOCKMODE lockmode);
89 extern void index_close(Relation relation, LOCKMODE lockmode);
90
91 extern bool index_insert(Relation indexRelation,
92                          Datum *values, bool *isnull,
93                          ItemPointer heap_t_ctid,
94                          Relation heapRelation,
95                          bool check_uniqueness);
96
97 extern IndexScanDesc index_beginscan(Relation heapRelation,
98                                 Relation indexRelation,
99                                 Snapshot snapshot,
100                                 int nkeys, ScanKey key);
101 extern IndexScanDesc index_beginscan_multi(Relation indexRelation,
102                                           Snapshot snapshot,
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);
114
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,
122                                 uint16 procnum);
123 extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
124                                   uint16 procnum);
125
126 /*
127  * index access method support routines (in genam.c)
128  */
129 extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
130                                          int nkeys, ScanKey key);
131 extern void IndexScanEnd(IndexScanDesc scan);
132
133 /*
134  * heap-or-index access to system catalogs (in genam.c)
135  */
136 extern SysScanDesc systable_beginscan(Relation heapRelation,
137                                    Oid indexId,
138                                    bool indexOK,
139                                    Snapshot snapshot,
140                                    int nkeys, ScanKey key);
141 extern HeapTuple systable_getnext(SysScanDesc sysscan);
142 extern void systable_endscan(SysScanDesc sysscan);
143
144 #endif   /* GENAM_H */