Header And Logo

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

relfilenode.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * relfilenode.h
00004  *    Physical access information for relations.
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/storage/relfilenode.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef RELFILENODE_H
00015 #define RELFILENODE_H
00016 
00017 #include "storage/backendid.h"
00018 
00019 /*
00020  * The physical storage of a relation consists of one or more forks. The
00021  * main fork is always created, but in addition to that there can be
00022  * additional forks for storing various metadata. ForkNumber is used when
00023  * we need to refer to a specific fork in a relation.
00024  */
00025 typedef enum ForkNumber
00026 {
00027     InvalidForkNumber = -1,
00028     MAIN_FORKNUM = 0,
00029     FSM_FORKNUM,
00030     VISIBILITYMAP_FORKNUM,
00031     INIT_FORKNUM
00032 
00033     /*
00034      * NOTE: if you add a new fork, change MAX_FORKNUM below and update the
00035      * forkNames array in catalog.c
00036      */
00037 } ForkNumber;
00038 
00039 #define MAX_FORKNUM     INIT_FORKNUM
00040 
00041 /*
00042  * RelFileNode must provide all that we need to know to physically access
00043  * a relation, with the exception of the backend ID, which can be provided
00044  * separately. Note, however, that a "physical" relation is comprised of
00045  * multiple files on the filesystem, as each fork is stored as a separate
00046  * file, and each fork can be divided into multiple segments. See md.c.
00047  *
00048  * spcNode identifies the tablespace of the relation.  It corresponds to
00049  * pg_tablespace.oid.
00050  *
00051  * dbNode identifies the database of the relation.  It is zero for
00052  * "shared" relations (those common to all databases of a cluster).
00053  * Nonzero dbNode values correspond to pg_database.oid.
00054  *
00055  * relNode identifies the specific relation.  relNode corresponds to
00056  * pg_class.relfilenode (NOT pg_class.oid, because we need to be able
00057  * to assign new physical files to relations in some situations).
00058  * Notice that relNode is only unique within a particular database.
00059  *
00060  * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is
00061  * zero.  We support shared relations only in the "global" tablespace.
00062  *
00063  * Note: in pg_class we allow reltablespace == 0 to denote that the
00064  * relation is stored in its database's "default" tablespace (as
00065  * identified by pg_database.dattablespace).  However this shorthand
00066  * is NOT allowed in RelFileNode structs --- the real tablespace ID
00067  * must be supplied when setting spcNode.
00068  *
00069  * Note: in pg_class, relfilenode can be zero to denote that the relation
00070  * is a "mapped" relation, whose current true filenode number is available
00071  * from relmapper.c.  Again, this case is NOT allowed in RelFileNodes.
00072  *
00073  * Note: various places use RelFileNode in hashtable keys.  Therefore,
00074  * there *must not* be any unused padding bytes in this struct.  That
00075  * should be safe as long as all the fields are of type Oid.
00076  */
00077 typedef struct RelFileNode
00078 {
00079     Oid         spcNode;        /* tablespace */
00080     Oid         dbNode;         /* database */
00081     Oid         relNode;        /* relation */
00082 } RelFileNode;
00083 
00084 /*
00085  * Augmenting a relfilenode with the backend ID provides all the information
00086  * we need to locate the physical storage.  The backend ID is InvalidBackendId
00087  * for regular relations (those accessible to more than one backend), or the
00088  * owning backend's ID for backend-local relations.  Backend-local relations
00089  * are always transient and removed in case of a database crash; they are
00090  * never WAL-logged or fsync'd.
00091  */
00092 typedef struct RelFileNodeBackend
00093 {
00094     RelFileNode node;
00095     BackendId   backend;
00096 } RelFileNodeBackend;
00097 
00098 #define RelFileNodeBackendIsTemp(rnode) \
00099     ((rnode).backend != InvalidBackendId)
00100 
00101 /*
00102  * Note: RelFileNodeEquals and RelFileNodeBackendEquals compare relNode first
00103  * since that is most likely to be different in two unequal RelFileNodes.  It
00104  * is probably redundant to compare spcNode if the other fields are found equal,
00105  * but do it anyway to be sure.  Likewise for checking the backend ID in
00106  * RelFileNodeBackendEquals.
00107  */
00108 #define RelFileNodeEquals(node1, node2) \
00109     ((node1).relNode == (node2).relNode && \
00110      (node1).dbNode == (node2).dbNode && \
00111      (node1).spcNode == (node2).spcNode)
00112 
00113 #define RelFileNodeBackendEquals(node1, node2) \
00114     ((node1).node.relNode == (node2).node.relNode && \
00115      (node1).node.dbNode == (node2).node.dbNode && \
00116      (node1).backend == (node2).backend && \
00117      (node1).node.spcNode == (node2).node.spcNode)
00118 
00119 #endif   /* RELFILENODE_H */