]> granicus.if.org Git - postgresql/blob - src/include/storage/relfilenode.h
90a0f642d40811ca21e8c8b2442340e7022a198a
[postgresql] / src / include / storage / relfilenode.h
1 /*-------------------------------------------------------------------------
2  *
3  * relfilenode.h
4  *        Physical access information for relations.
5  *
6  *
7  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/storage/relfilenode.h,v 1.21 2008/12/03 13:05:22 heikki Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef RELFILENODE_H
15 #define RELFILENODE_H
16
17 /*
18  * The physical storage of a relation consists of one or more forks. The
19  * main fork is always created, but in addition to that there can be
20  * additional forks for storing various metadata. ForkNumber is used when
21  * we need to refer to a specific fork in a relation.
22  */
23 typedef enum ForkNumber
24 {
25         InvalidForkNumber = -1,
26         MAIN_FORKNUM = 0,
27         FSM_FORKNUM,
28         VISIBILITYMAP_FORKNUM
29         /*
30          * NOTE: if you add a new fork, change MAX_FORKNUM below and update the
31          * forkNames array in catalog.c
32          */
33 } ForkNumber;
34
35 #define MAX_FORKNUM             VISIBILITYMAP_FORKNUM
36
37 /*
38  * RelFileNode must provide all that we need to know to physically access
39  * a relation. Note, however, that a "physical" relation is comprised of
40  * multiple files on the filesystem, as each fork is stored as a separate
41  * file, and each fork can be divided into multiple segments. See md.c.
42  *
43  * spcNode identifies the tablespace of the relation.  It corresponds to
44  * pg_tablespace.oid.
45  *
46  * dbNode identifies the database of the relation.      It is zero for
47  * "shared" relations (those common to all databases of a cluster).
48  * Nonzero dbNode values correspond to pg_database.oid.
49  *
50  * relNode identifies the specific relation.  relNode corresponds to
51  * pg_class.relfilenode (NOT pg_class.oid, because we need to be able
52  * to assign new physical files to relations in some situations).
53  * Notice that relNode is only unique within a particular database.
54  *
55  * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is
56  * zero.  We support shared relations only in the "global" tablespace.
57  *
58  * Note: in pg_class we allow reltablespace == 0 to denote that the
59  * relation is stored in its database's "default" tablespace (as
60  * identified by pg_database.dattablespace).  However this shorthand
61  * is NOT allowed in RelFileNode structs --- the real tablespace ID
62  * must be supplied when setting spcNode.
63  */
64 typedef struct RelFileNode
65 {
66         Oid                     spcNode;                /* tablespace */
67         Oid                     dbNode;                 /* database */
68         Oid                     relNode;                /* relation */
69 } RelFileNode;
70
71 /*
72  * Note: RelFileNodeEquals compares relNode first since that is most likely
73  * to be different in two unequal RelFileNodes.  It is probably redundant
74  * to compare spcNode if the other two fields are found equal, but do it
75  * anyway to be sure.
76  */
77 #define RelFileNodeEquals(node1, node2) \
78         ((node1).relNode == (node2).relNode && \
79          (node1).dbNode == (node2).dbNode && \
80          (node1).spcNode == (node2).spcNode)
81
82 #endif   /* RELFILENODE_H */