Eneboo - Documentación para desarrolladores
src/libpq/include/utils/rel.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * rel.h
00004  *        POSTGRES relation descriptor (a/k/a relcache entry) definitions.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.87 2005/10/15 02:49:46 momjian Exp $
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef REL_H
00015 #define REL_H
00016 
00017 #include "access/tupdesc.h"
00018 #include "catalog/pg_am.h"
00019 #include "catalog/pg_class.h"
00020 #include "catalog/pg_index.h"
00021 #include "fmgr.h"
00022 #include "rewrite/prs2lock.h"
00023 #include "storage/block.h"
00024 #include "storage/relfilenode.h"
00025 
00026 
00027 /*
00028  * LockRelId and LockInfo really belong to lmgr.h, but it's more convenient
00029  * to declare them here so we can have a LockInfoData field in a Relation.
00030  */
00031 
00032 typedef struct LockRelId
00033 {
00034         Oid                     relId;                  /* a relation identifier */
00035         Oid                     dbId;                   /* a database identifier */
00036 } LockRelId;
00037 
00038 typedef struct LockInfoData
00039 {
00040         LockRelId       lockRelId;
00041 } LockInfoData;
00042 
00043 typedef LockInfoData *LockInfo;
00044 
00045 /*
00046  * Likewise, this struct really belongs to trigger.h, but for convenience
00047  * we put it here.
00048  */
00049 typedef struct Trigger
00050 {
00051         Oid                     tgoid;                  /* OID of trigger (pg_trigger row) */
00052         /* Remaining fields are copied from pg_trigger, see pg_trigger.h */
00053         char       *tgname;
00054         Oid                     tgfoid;
00055         int16           tgtype;
00056         bool            tgenabled;
00057         bool            tgisconstraint;
00058         Oid                     tgconstrrelid;
00059         bool            tgdeferrable;
00060         bool            tginitdeferred;
00061         int16           tgnargs;
00062         int16           tgnattr;
00063         int16      *tgattr;
00064         char      **tgargs;
00065 } Trigger;
00066 
00067 typedef struct TriggerDesc
00068 {
00069         /*
00070          * Index data to identify which triggers are which.  Since each trigger
00071          * can appear in more than one class, for each class we provide a list of
00072          * integer indexes into the triggers array.
00073          */
00074 #define TRIGGER_NUM_EVENT_CLASSES  3
00075 
00076         uint16          n_before_statement[TRIGGER_NUM_EVENT_CLASSES];
00077         uint16          n_before_row[TRIGGER_NUM_EVENT_CLASSES];
00078         uint16          n_after_row[TRIGGER_NUM_EVENT_CLASSES];
00079         uint16          n_after_statement[TRIGGER_NUM_EVENT_CLASSES];
00080         int                *tg_before_statement[TRIGGER_NUM_EVENT_CLASSES];
00081         int                *tg_before_row[TRIGGER_NUM_EVENT_CLASSES];
00082         int                *tg_after_row[TRIGGER_NUM_EVENT_CLASSES];
00083         int                *tg_after_statement[TRIGGER_NUM_EVENT_CLASSES];
00084 
00085         /* The actual array of triggers is here */
00086         Trigger    *triggers;
00087         int                     numtriggers;
00088 } TriggerDesc;
00089 
00090 
00091 /*
00092  * Same for the statistics collector data in Relation and scan data.
00093  */
00094 typedef struct PgStat_Info
00095 {
00096         void       *tabentry;
00097 } PgStat_Info;
00098 
00099 
00100 /*
00101  * Cached lookup information for the index access method functions defined
00102  * by the pg_am row associated with an index relation.
00103  */
00104 typedef struct RelationAmInfo
00105 {
00106         FmgrInfo        aminsert;
00107         FmgrInfo        ambeginscan;
00108         FmgrInfo        amgettuple;
00109         FmgrInfo        amgetmulti;
00110         FmgrInfo        amrescan;
00111         FmgrInfo        amendscan;
00112         FmgrInfo        ammarkpos;
00113         FmgrInfo        amrestrpos;
00114         FmgrInfo        ambuild;
00115         FmgrInfo        ambulkdelete;
00116         FmgrInfo        amvacuumcleanup;
00117         FmgrInfo        amcostestimate;
00118 } RelationAmInfo;
00119 
00120 
00121 /*
00122  * Here are the contents of a relation cache entry.
00123  */
00124 
00125 typedef struct RelationData
00126 {
00127         RelFileNode rd_node;            /* relation physical identifier */
00128         /* use "struct" here to avoid needing to include smgr.h: */
00129         struct SMgrRelationData *rd_smgr;       /* cached file handle, or NULL */
00130         BlockNumber rd_targblock;       /* current insertion target block, or
00131                                                                  * InvalidBlockNumber */
00132         int                     rd_refcnt;              /* reference count */
00133         bool            rd_istemp;              /* rel uses the local buffer mgr */
00134         bool            rd_isnailed;    /* rel is nailed in cache */
00135         bool            rd_isvalid;             /* relcache entry is valid */
00136         char            rd_indexvalid;  /* state of rd_indexlist: 0 = not valid, 1 =
00137                                                                  * valid, 2 = temporarily forced */
00138         SubTransactionId rd_createSubid;        /* rel was created in current xact */
00139 
00140         /*
00141          * rd_createSubid is the ID of the highest subtransaction the rel has
00142          * survived into; or zero if the rel was not created in the current top
00143          * transaction.  This should be relied on only for optimization purposes;
00144          * it is possible for new-ness to be "forgotten" (eg, after CLUSTER).
00145          */
00146         Form_pg_class rd_rel;           /* RELATION tuple */
00147         TupleDesc       rd_att;                 /* tuple descriptor */
00148         Oid                     rd_id;                  /* relation's object id */
00149         List       *rd_indexlist;       /* list of OIDs of indexes on relation */
00150         Oid                     rd_oidindex;    /* OID of unique index on OID, if any */
00151         LockInfoData rd_lockInfo;       /* lock mgr's info for locking relation */
00152         RuleLock   *rd_rules;           /* rewrite rules */
00153         MemoryContext rd_rulescxt;      /* private memory cxt for rd_rules, if any */
00154         TriggerDesc *trigdesc;          /* Trigger info, or NULL if rel has none */
00155 
00156         /* These are non-NULL only for an index relation: */
00157         Form_pg_index rd_index;         /* pg_index tuple describing this index */
00158         struct HeapTupleData *rd_indextuple;            /* all of pg_index tuple */
00159         /* "struct HeapTupleData *" avoids need to include htup.h here  */
00160         oidvector  *rd_indclass;        /* extracted pointer to rd_index field */
00161         Form_pg_am      rd_am;                  /* pg_am tuple for index's AM */
00162 
00163         /*
00164          * index access support info (used only for an index relation)
00165          *
00166          * Note: only default operators and support procs for each opclass are
00167          * cached, namely those with subtype zero.      The arrays are indexed by
00168          * strategy or support number, which is a sufficient identifier given that
00169          * restriction.
00170          */
00171         MemoryContext rd_indexcxt;      /* private memory cxt for this stuff */
00172         RelationAmInfo *rd_aminfo;      /* lookup info for funcs found in pg_am */
00173         Oid                *rd_operator;        /* OIDs of index operators */
00174         RegProcedure *rd_support;       /* OIDs of support procedures */
00175         FmgrInfo   *rd_supportinfo; /* lookup info for support procedures */
00176         List       *rd_indexprs;        /* index expression trees, if any */
00177         List       *rd_indpred;         /* index predicate tree, if any */
00178 
00179         /* statistics collection area */
00180         PgStat_Info pgstat_info;
00181 } RelationData;
00182 
00183 typedef RelationData *Relation;
00184 
00185 
00186 /* ----------------
00187  *              RelationPtr is used in the executor to support index scans
00188  *              where we have to keep track of several index relations in an
00189  *              array.  -cim 9/10/89
00190  * ----------------
00191  */
00192 typedef Relation *RelationPtr;
00193 
00194 
00195 /*
00196  * RelationIsValid
00197  *              True iff relation descriptor is valid.
00198  */
00199 #define RelationIsValid(relation) PointerIsValid(relation)
00200 
00201 #define InvalidRelation ((Relation) NULL)
00202 
00203 /*
00204  * RelationHasReferenceCountZero
00205  *              True iff relation reference count is zero.
00206  *
00207  * Note:
00208  *              Assumes relation descriptor is valid.
00209  */
00210 #define RelationHasReferenceCountZero(relation) \
00211                 ((bool)((relation)->rd_refcnt == 0))
00212 
00213 /*
00214  * RelationGetForm
00215  *              Returns pg_class tuple for a relation.
00216  *
00217  * Note:
00218  *              Assumes relation descriptor is valid.
00219  */
00220 #define RelationGetForm(relation) ((relation)->rd_rel)
00221 
00222 /*
00223  * RelationGetRelid
00224  *              Returns the OID of the relation
00225  */
00226 #define RelationGetRelid(relation) ((relation)->rd_id)
00227 
00228 /*
00229  * RelationGetNumberOfAttributes
00230  *              Returns the number of attributes in a relation.
00231  */
00232 #define RelationGetNumberOfAttributes(relation) ((relation)->rd_rel->relnatts)
00233 
00234 /*
00235  * RelationGetDescr
00236  *              Returns tuple descriptor for a relation.
00237  */
00238 #define RelationGetDescr(relation) ((relation)->rd_att)
00239 
00240 /*
00241  * RelationGetRelationName
00242  *              Returns the rel's name.
00243  *
00244  * Note that the name is only unique within the containing namespace.
00245  */
00246 #define RelationGetRelationName(relation) \
00247         (NameStr((relation)->rd_rel->relname))
00248 
00249 /*
00250  * RelationGetNamespace
00251  *              Returns the rel's namespace OID.
00252  */
00253 #define RelationGetNamespace(relation) \
00254         ((relation)->rd_rel->relnamespace)
00255 
00256 /*
00257  * RelationOpenSmgr
00258  *              Open the relation at the smgr level, if not already done.
00259  */
00260 #define RelationOpenSmgr(relation) \
00261         do { \
00262                 if ((relation)->rd_smgr == NULL) \
00263                         smgrsetowner(&((relation)->rd_smgr), smgropen((relation)->rd_node)); \
00264         } while (0)
00265 
00266 /*
00267  * RelationCloseSmgr
00268  *              Close the relation at the smgr level, if not already done.
00269  *
00270  * Note: smgrclose should unhook from owner pointer, hence the Assert.
00271  */
00272 #define RelationCloseSmgr(relation) \
00273         do { \
00274                 if ((relation)->rd_smgr != NULL) \
00275                 { \
00276                         smgrclose((relation)->rd_smgr); \
00277                         Assert((relation)->rd_smgr == NULL); \
00278                 } \
00279         } while (0)
00280 
00281 /*
00282  * RELATION_IS_LOCAL
00283  *              If a rel is either temp or newly created in the current transaction,
00284  *              it can be assumed to be visible only to the current backend.
00285  *
00286  * Beware of multiple eval of argument
00287  */
00288 #define RELATION_IS_LOCAL(relation) \
00289         ((relation)->rd_istemp || \
00290          (relation)->rd_createSubid != InvalidSubTransactionId)
00291 
00292 /* routines in utils/cache/relcache.c */
00293 extern void RelationIncrementReferenceCount(Relation rel);
00294 extern void RelationDecrementReferenceCount(Relation rel);
00295 
00296 #endif   /* REL_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'