Header And Logo

PostgreSQL
| The world's most advanced open source database.

genam.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * genam.h
00004  *    POSTGRES generalized index access method definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/access/genam.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef GENAM_H
00015 #define GENAM_H
00016 
00017 #include "access/sdir.h"
00018 #include "access/skey.h"
00019 #include "nodes/tidbitmap.h"
00020 #include "storage/lock.h"
00021 #include "utils/relcache.h"
00022 #include "utils/snapshot.h"
00023 
00024 /*
00025  * Struct for statistics returned by ambuild
00026  */
00027 typedef struct IndexBuildResult
00028 {
00029     double      heap_tuples;    /* # of tuples seen in parent table */
00030     double      index_tuples;   /* # of tuples inserted into index */
00031 } IndexBuildResult;
00032 
00033 /*
00034  * Struct for input arguments passed to ambulkdelete and amvacuumcleanup
00035  *
00036  * num_heap_tuples is accurate only when estimated_count is false;
00037  * otherwise it's just an estimate (currently, the estimate is the
00038  * prior value of the relation's pg_class.reltuples field).  It will
00039  * always just be an estimate during ambulkdelete.
00040  */
00041 typedef struct IndexVacuumInfo
00042 {
00043     Relation    index;          /* the index being vacuumed */
00044     bool        analyze_only;   /* ANALYZE (without any actual vacuum) */
00045     bool        estimated_count;    /* num_heap_tuples is an estimate */
00046     int         message_level;  /* ereport level for progress messages */
00047     double      num_heap_tuples;    /* tuples remaining in heap */
00048     BufferAccessStrategy strategy;      /* access strategy for reads */
00049 } IndexVacuumInfo;
00050 
00051 /*
00052  * Struct for statistics returned by ambulkdelete and amvacuumcleanup
00053  *
00054  * This struct is normally allocated by the first ambulkdelete call and then
00055  * passed along through subsequent ones until amvacuumcleanup; however,
00056  * amvacuumcleanup must be prepared to allocate it in the case where no
00057  * ambulkdelete calls were made (because no tuples needed deletion).
00058  * Note that an index AM could choose to return a larger struct
00059  * of which this is just the first field; this provides a way for ambulkdelete
00060  * to communicate additional private data to amvacuumcleanup.
00061  *
00062  * Note: pages_removed is the amount by which the index physically shrank,
00063  * if any (ie the change in its total size on disk).  pages_deleted and
00064  * pages_free refer to free space within the index file.  Some index AMs
00065  * may compute num_index_tuples by reference to num_heap_tuples, in which
00066  * case they should copy the estimated_count field from IndexVacuumInfo.
00067  */
00068 typedef struct IndexBulkDeleteResult
00069 {
00070     BlockNumber num_pages;      /* pages remaining in index */
00071     BlockNumber pages_removed;  /* # removed during vacuum operation */
00072     bool        estimated_count;    /* num_index_tuples is an estimate */
00073     double      num_index_tuples;       /* tuples remaining */
00074     double      tuples_removed; /* # removed during vacuum operation */
00075     BlockNumber pages_deleted;  /* # unused pages in index */
00076     BlockNumber pages_free;     /* # pages available for reuse */
00077 } IndexBulkDeleteResult;
00078 
00079 /* Typedef for callback function to determine if a tuple is bulk-deletable */
00080 typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
00081 
00082 /* struct definitions appear in relscan.h */
00083 typedef struct IndexScanDescData *IndexScanDesc;
00084 typedef struct SysScanDescData *SysScanDesc;
00085 
00086 /*
00087  * Enumeration specifying the type of uniqueness check to perform in
00088  * index_insert().
00089  *
00090  * UNIQUE_CHECK_YES is the traditional Postgres immediate check, possibly
00091  * blocking to see if a conflicting transaction commits.
00092  *
00093  * For deferrable unique constraints, UNIQUE_CHECK_PARTIAL is specified at
00094  * insertion time.  The index AM should test if the tuple is unique, but
00095  * should not throw error, block, or prevent the insertion if the tuple
00096  * appears not to be unique.  We'll recheck later when it is time for the
00097  * constraint to be enforced.  The AM must return true if the tuple is
00098  * known unique, false if it is possibly non-unique.  In the "true" case
00099  * it is safe to omit the later recheck.
00100  *
00101  * When it is time to recheck the deferred constraint, a pseudo-insertion
00102  * call is made with UNIQUE_CHECK_EXISTING.  The tuple is already in the
00103  * index in this case, so it should not be inserted again.  Rather, just
00104  * check for conflicting live tuples (possibly blocking).
00105  */
00106 typedef enum IndexUniqueCheck
00107 {
00108     UNIQUE_CHECK_NO,            /* Don't do any uniqueness checking */
00109     UNIQUE_CHECK_YES,           /* Enforce uniqueness at insertion time */
00110     UNIQUE_CHECK_PARTIAL,       /* Test uniqueness, but no error */
00111     UNIQUE_CHECK_EXISTING       /* Check if existing tuple is unique */
00112 } IndexUniqueCheck;
00113 
00114 
00115 /*
00116  * generalized index_ interface routines (in indexam.c)
00117  */
00118 
00119 /*
00120  * IndexScanIsValid
00121  *      True iff the index scan is valid.
00122  */
00123 #define IndexScanIsValid(scan) PointerIsValid(scan)
00124 
00125 extern Relation index_open(Oid relationId, LOCKMODE lockmode);
00126 extern void index_close(Relation relation, LOCKMODE lockmode);
00127 
00128 extern bool index_insert(Relation indexRelation,
00129              Datum *values, bool *isnull,
00130              ItemPointer heap_t_ctid,
00131              Relation heapRelation,
00132              IndexUniqueCheck checkUnique);
00133 
00134 extern IndexScanDesc index_beginscan(Relation heapRelation,
00135                 Relation indexRelation,
00136                 Snapshot snapshot,
00137                 int nkeys, int norderbys);
00138 extern IndexScanDesc index_beginscan_bitmap(Relation indexRelation,
00139                        Snapshot snapshot,
00140                        int nkeys);
00141 extern void index_rescan(IndexScanDesc scan,
00142              ScanKey keys, int nkeys,
00143              ScanKey orderbys, int norderbys);
00144 extern void index_endscan(IndexScanDesc scan);
00145 extern void index_markpos(IndexScanDesc scan);
00146 extern void index_restrpos(IndexScanDesc scan);
00147 extern ItemPointer index_getnext_tid(IndexScanDesc scan,
00148                   ScanDirection direction);
00149 extern HeapTuple index_fetch_heap(IndexScanDesc scan);
00150 extern HeapTuple index_getnext(IndexScanDesc scan, ScanDirection direction);
00151 extern int64 index_getbitmap(IndexScanDesc scan, TIDBitmap *bitmap);
00152 
00153 extern IndexBulkDeleteResult *index_bulk_delete(IndexVacuumInfo *info,
00154                   IndexBulkDeleteResult *stats,
00155                   IndexBulkDeleteCallback callback,
00156                   void *callback_state);
00157 extern IndexBulkDeleteResult *index_vacuum_cleanup(IndexVacuumInfo *info,
00158                      IndexBulkDeleteResult *stats);
00159 extern bool index_can_return(Relation indexRelation);
00160 extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
00161                 uint16 procnum);
00162 extern FmgrInfo *index_getprocinfo(Relation irel, AttrNumber attnum,
00163                   uint16 procnum);
00164 
00165 /*
00166  * index access method support routines (in genam.c)
00167  */
00168 extern IndexScanDesc RelationGetIndexScan(Relation indexRelation,
00169                      int nkeys, int norderbys);
00170 extern void IndexScanEnd(IndexScanDesc scan);
00171 extern char *BuildIndexValueDescription(Relation indexRelation,
00172                            Datum *values, bool *isnull);
00173 
00174 /*
00175  * heap-or-index access to system catalogs (in genam.c)
00176  */
00177 extern SysScanDesc systable_beginscan(Relation heapRelation,
00178                    Oid indexId,
00179                    bool indexOK,
00180                    Snapshot snapshot,
00181                    int nkeys, ScanKey key);
00182 extern HeapTuple systable_getnext(SysScanDesc sysscan);
00183 extern bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup);
00184 extern void systable_endscan(SysScanDesc sysscan);
00185 extern SysScanDesc systable_beginscan_ordered(Relation heapRelation,
00186                            Relation indexRelation,
00187                            Snapshot snapshot,
00188                            int nkeys, ScanKey key);
00189 extern HeapTuple systable_getnext_ordered(SysScanDesc sysscan,
00190                          ScanDirection direction);
00191 extern void systable_endscan_ordered(SysScanDesc sysscan);
00192 
00193 #endif   /* GENAM_H */