~ubuntu-branches/debian/sid/postgresql-9.3/sid

« back to all changes in this revision

Viewing changes to src/include/access/genam.h

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 05:39:52 UTC
  • Revision ID: package-import@ubuntu.com-20130508053952-1j7uilp7mjtrvq8q
Tags: upstream-9.3~beta1
ImportĀ upstreamĀ versionĀ 9.3~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * genam.h
 
4
 *        POSTGRES generalized index access method definitions.
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * src/include/access/genam.h
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef GENAM_H
 
15
#define GENAM_H
 
16
 
 
17
#include "access/sdir.h"
 
18
#include "access/skey.h"
 
19
#include "nodes/tidbitmap.h"
 
20
#include "storage/lock.h"
 
21
#include "utils/relcache.h"
 
22
#include "utils/snapshot.h"
 
23
 
 
24
/*
 
25
 * Struct for statistics returned by ambuild
 
26
 */
 
27
typedef struct IndexBuildResult
 
28
{
 
29
        double          heap_tuples;    /* # of tuples seen in parent table */
 
30
        double          index_tuples;   /* # of tuples inserted into index */
 
31
} IndexBuildResult;
 
32
 
 
33
/*
 
34
 * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
 
35
 *
 
36
 * num_heap_tuples is accurate only when estimated_count is false;
 
37
 * otherwise it's just an estimate (currently, the estimate is the
 
38
 * prior value of the relation's pg_class.reltuples field).  It will
 
39
 * always just be an estimate during ambulkdelete.
 
40
 */
 
41
typedef struct IndexVacuumInfo
 
42
{
 
43
        Relation        index;                  /* the index being vacuumed */
 
44
        bool            analyze_only;   /* ANALYZE (without any actual vacuum) */
 
45
        bool            estimated_count;        /* num_heap_tuples is an estimate */
 
46
        int                     message_level;  /* ereport level for progress messages */
 
47
        double          num_heap_tuples;        /* tuples remaining in heap */
 
48
        BufferAccessStrategy strategy;          /* access strategy for reads */
 
49
} IndexVacuumInfo;
 
50
 
 
51
/*
 
52
 * Struct for statistics returned by ambulkdelete and amvacuumcleanup
 
53
 *
 
54
 * This struct is normally allocated by the first ambulkdelete call and then
 
55
 * passed along through subsequent ones until amvacuumcleanup; however,
 
56
 * amvacuumcleanup must be prepared to allocate it in the case where no
 
57
 * ambulkdelete calls were made (because no tuples needed deletion).
 
58
 * Note that an index AM could choose to return a larger struct
 
59
 * of which this is just the first field; this provides a way for ambulkdelete
 
60
 * to communicate additional private data to amvacuumcleanup.
 
61
 *
 
62
 * Note: pages_removed is the amount by which the index physically shrank,
 
63
 * if any (ie the change in its total size on disk).  pages_deleted and
 
64
 * pages_free refer to free space within the index file.  Some index AMs
 
65
 * may compute num_index_tuples by reference to num_heap_tuples, in which
 
66
 * case they should copy the estimated_count field from IndexVacuumInfo.
 
67
 */
 
68
typedef struct IndexBulkDeleteResult
 
69
{
 
70
        BlockNumber num_pages;          /* pages remaining in index */
 
71
        BlockNumber pages_removed;      /* # removed during vacuum operation */
 
72
        bool            estimated_count;        /* num_index_tuples is an estimate */
 
73
        double          num_index_tuples;               /* tuples remaining */
 
74
        double          tuples_removed; /* # removed during vacuum operation */
 
75
        BlockNumber pages_deleted;      /* # unused pages in index */
 
76
        BlockNumber pages_free;         /* # pages available for reuse */
 
77
} IndexBulkDeleteResult;
 
78
 
 
79
/* Typedef for callback function to determine if a tuple is bulk-deletable */
 
80
typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
 
81
 
 
82
/* struct definitions appear in relscan.h */
 
83
typedef struct IndexScanDescData *IndexScanDesc;
 
84
typedef struct SysScanDescData *SysScanDesc;
 
85
 
 
86
/*
 
87
 * Enumeration specifying the type of uniqueness check to perform in
 
88
 * index_insert().
 
89
 *
 
90
 * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
 
91
 * blocking to see if a conflicting transaction commits.
 
92
 *
 
93
 * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
 
94
 * insertion time.      The index AM should test if the tuple is unique, but
 
95
 * should not throw error, block, or prevent the insertion if the tuple
 
96
 * appears not to be unique.  We'll recheck later when it is time for the
 
97
 * constraint to be enforced.  The AM must return true if the tuple is
 
98
 * known unique, false if it is possibly non-unique.  In the "true" case
 
99
 * it is safe to omit the later recheck.
 
100
 *
 
101
 * When it is time to recheck the deferred constraint, a pseudo-insertion
 
102
 * call is made with UNIQUE_CHECK_EXISTING.  The tuple is already in the
 
103
 * index in this case, so it should not be inserted again.      Rather, just
 
104
 * check for conflicting live tuples (possibly blocking).
 
105
 */
 
106
typedef enum IndexUniqueCheck
 
107
{
 
108
        UNIQUE_CHECK_NO,                        /* Don't do any uniqueness checking */
 
109
        UNIQUE_CHECK_YES,                       /* Enforce uniqueness at insertion time */
 
110
        UNIQUE_CHECK_PARTIAL,           /* Test uniqueness, but no error */
 
111
        UNIQUE_CHECK_EXISTING           /* Check if existing tuple is unique */
 
112
} IndexUniqueCheck;
 
113
 
 
114
 
 
115
/*
 
116
 * generalized index_ interface routines (in indexam.c)
 
117
 */
 
118
 
 
119
/*
 
120
 * IndexScanIsValid
 
121
 *              True iff the index scan is valid.
 
122
 */
 
123
#define IndexScanIsValid(scan) PointerIsValid(scan)
 
124
 
 
125
extern Relation index_open(Oid relationId, LOCKMODE lockmode);
 
126
extern void index_close(Relation relation, LOCKMODE lockmode);
 
127
 
 
128
extern bool index_insert(Relation indexRelation,
 
129
                         Datum *values, bool *isnull,
 
130
                         ItemPointer heap_t_ctid,
 
131
                         Relation heapRelation,
 
132
                         IndexUniqueCheck checkUnique);
 
133
 
 
134
extern IndexScanDesc index_beginscan(Relation heapRelation,
 
135
                                Relation indexRelation,
 
136
                                Snapshot snapshot,
 
137
                                int nkeys, int norderbys);
 
138
extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
 
139
                                           Snapshot snapshot,
 
140
                                           int nkeys);
 
141
extern void index_rescan(IndexScanDesc scan,
 
142
                         ScanKey keys, int nkeys,
 
143
                         ScanKey orderbys, int norderbys);
 
144
extern void index_endscan(IndexScanDesc scan);
 
145
extern void index_markpos(IndexScanDesc scan);
 
146
extern void index_restrpos(IndexScanDesc scan);
 
147
extern ItemPointer index_getnext_tid(IndexScanDesc scan,
 
148
                                  ScanDirection direction);
 
149
extern HeapTuple index_fetch_heap(IndexScanDesc scan);
 
150
extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
 
151
extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
 
152
 
 
153
extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
 
154
                                  IndexBulkDeleteResult *stats,
 
155
                                  IndexBulkDeleteCallback callback,
 
156
                                  void *callback_state);
 
157
extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
 
158
                                         IndexBulkDeleteResult *stats);
 
159
extern bool index_can_return(Relation indexRelation);
 
160
extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
 
161
                                uint16 procnum);
 
162
extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
 
163
                                  uint16 procnum);
 
164
 
 
165
/*
 
166
 * index access method support routines (in genam.c)
 
167
 */
 
168
extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
 
169
                                         int nkeys, int norderbys);
 
170
extern void IndexScanEnd(IndexScanDesc scan);
 
171
extern char *BuildIndexValueDescription(Relation indexRelation,
 
172
                                                   Datum *values, bool *isnull);
 
173
 
 
174
/*
 
175
 * heap-or-index access to system catalogs (in genam.c)
 
176
 */
 
177
extern SysScanDesc systable_beginscan(Relation heapRelation,
 
178
                                   Oid indexId,
 
179
                                   bool indexOK,
 
180
                                   Snapshot snapshot,
 
181
                                   int nkeys, ScanKey key);
 
182
extern HeapTuple systable_getnext(SysScanDesc sysscan);
 
183
extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
 
184
extern void systable_endscan(SysScanDesc sysscan);
 
185
extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
 
186
                                                   Relation indexRelation,
 
187
                                                   Snapshot snapshot,
 
188
                                                   int nkeys, ScanKey key);
 
189
extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
 
190
                                                 ScanDirection direction);
 
191
extern void systable_endscan_ordered(SysScanDesc sysscan);
 
192
 
 
193
#endif   /* GENAM_H */