]> granicus.if.org Git - postgresql/blob - src/include/access/genam.h
Skip ambulkdelete scan if there's nothing to delete and the index is not
[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-2005, 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.57 2006/02/11 23:31:34 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 bulk-delete operation
25  *
26  * This is now also passed to the index AM's vacuum-cleanup operation,
27  * if it has one, which can modify the results as needed.  Note that
28  * an index AM could choose to have bulk-delete return a larger struct
29  * of which this is just the first field; this provides a way for bulk-delete
30  * to communicate additional private data to vacuum-cleanup.
31  *
32  * Note: pages_removed is the amount by which the index physically shrank,
33  * if any (ie the change in its total size on disk).  pages_deleted and
34  * pages_free refer to free space within the index file.
35  */
36 typedef struct IndexBulkDeleteResult
37 {
38         BlockNumber num_pages;          /* pages remaining in index */
39         BlockNumber pages_removed;      /* # removed by bulk-delete operation */
40         double          num_index_tuples;               /* tuples remaining */
41         double          tuples_removed; /* # removed by bulk-delete operation */
42         BlockNumber pages_deleted;      /* # unused pages in index */
43         BlockNumber pages_free;         /* # pages available for reuse */
44 } IndexBulkDeleteResult;
45
46 /* Typedef for callback function to determine if a tuple is bulk-deletable */
47 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
48
49 /* Struct for additional arguments passed to vacuum-cleanup operation */
50 typedef struct IndexVacuumCleanupInfo
51 {
52         bool            vacuum_full;    /* VACUUM FULL (we have exclusive lock) */
53         int                     message_level;  /* ereport level for progress messages */
54         double          num_heap_tuples;        /* tuples remaining in heap */
55 } IndexVacuumCleanupInfo;
56
57 /* Struct for heap-or-index scans of system tables */
58 typedef struct SysScanDescData
59 {
60         Relation        heap_rel;               /* catalog being scanned */
61         Relation        irel;                   /* NULL if doing heap scan */
62         HeapScanDesc scan;                      /* only valid in heap-scan case */
63         IndexScanDesc iscan;            /* only valid in index-scan case */
64 } SysScanDescData;
65
66 typedef SysScanDescData *SysScanDesc;
67
68
69 /*
70  * generalized index_ interface routines (in indexam.c)
71  */
72 extern Relation index_open(Oid relationId);
73 extern Relation index_openrv(const RangeVar *relation);
74 extern void index_close(Relation relation);
75 extern bool index_insert(Relation indexRelation,
76                          Datum *values, bool *isnull,
77                          ItemPointer heap_t_ctid,
78                          Relation heapRelation,
79                          bool check_uniqueness);
80
81 extern IndexScanDesc index_beginscan(Relation heapRelation,
82                                 Relation indexRelation,
83                                 bool need_index_lock,
84                                 Snapshot snapshot,
85                                 int nkeys, ScanKey key);
86 extern IndexScanDesc index_beginscan_multi(Relation indexRelation,
87                                           bool need_index_lock,
88                                           Snapshot snapshot,
89                                           int nkeys, ScanKey key);
90 extern void index_rescan(IndexScanDesc scan, ScanKey key);
91 extern void index_endscan(IndexScanDesc scan);
92 extern void index_markpos(IndexScanDesc scan);
93 extern void index_restrpos(IndexScanDesc scan);
94 extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
95 extern bool index_getnext_indexitem(IndexScanDesc scan,
96                                                 ScanDirection direction);
97 extern bool index_getmulti(IndexScanDesc scan,
98                            ItemPointer tids, int32 max_tids,
99                            int32 *returned_tids);
100
101 extern IndexBulkDeleteResult *index_bulk_delete(Relation indexRelation,
102                                   IndexBulkDeleteCallback callback,
103                                   void *callback_state);
104 extern IndexBulkDeleteResult *index_vacuum_cleanup(Relation indexRelation,
105                                          IndexVacuumCleanupInfo *info,
106                                          IndexBulkDeleteResult *stats);
107 extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
108                                 uint16 procnum);
109 extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
110                                   uint16 procnum);
111
112 /*
113  * index access method support routines (in genam.c)
114  */
115 extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
116                                          int nkeys, ScanKey key);
117 extern void IndexScanEnd(IndexScanDesc scan);
118
119 /*
120  * heap-or-index access to system catalogs (in genam.c)
121  */
122 extern SysScanDesc systable_beginscan(Relation heapRelation,
123                                    Oid indexId,
124                                    bool indexOK,
125                                    Snapshot snapshot,
126                                    int nkeys, ScanKey key);
127 extern HeapTuple systable_getnext(SysScanDesc sysscan);
128 extern void systable_endscan(SysScanDesc sysscan);
129
130 #endif   /* GENAM_H */