]> granicus.if.org Git - postgresql/blob - src/include/storage/relfilenode.h
Improve coding around the fsync request queue.
[postgresql] / src / include / storage / relfilenode.h
1 /*-------------------------------------------------------------------------
2  *
3  * relfilenode.h
4  *        Physical access information for relations.
5  *
6  *
7  * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/relfilenode.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef RELFILENODE_H
15 #define RELFILENODE_H
16
17 #include "storage/backendid.h"
18
19 /*
20  * The physical storage of a relation consists of one or more forks. The
21  * main fork is always created, but in addition to that there can be
22  * additional forks for storing various metadata. ForkNumber is used when
23  * we need to refer to a specific fork in a relation.
24  */
25 typedef enum ForkNumber
26 {
27         InvalidForkNumber = -1,
28         MAIN_FORKNUM = 0,
29         FSM_FORKNUM,
30         VISIBILITYMAP_FORKNUM,
31         INIT_FORKNUM
32
33         /*
34          * NOTE: if you add a new fork, change MAX_FORKNUM below and update the
35          * forkNames array in catalog.c
36          */
37 } ForkNumber;
38
39 #define MAX_FORKNUM             INIT_FORKNUM
40
41 /*
42  * RelFileNode must provide all that we need to know to physically access
43  * a relation, with the exception of the backend ID, which can be provided
44  * separately. Note, however, that a "physical" relation is comprised of
45  * multiple files on the filesystem, as each fork is stored as a separate
46  * file, and each fork can be divided into multiple segments. See md.c.
47  *
48  * spcNode identifies the tablespace of the relation.  It corresponds to
49  * pg_tablespace.oid.
50  *
51  * dbNode identifies the database of the relation.      It is zero for
52  * "shared" relations (those common to all databases of a cluster).
53  * Nonzero dbNode values correspond to pg_database.oid.
54  *
55  * relNode identifies the specific relation.  relNode corresponds to
56  * pg_class.relfilenode (NOT pg_class.oid, because we need to be able
57  * to assign new physical files to relations in some situations).
58  * Notice that relNode is only unique within a particular database.
59  *
60  * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is
61  * zero.  We support shared relations only in the "global" tablespace.
62  *
63  * Note: in pg_class we allow reltablespace == 0 to denote that the
64  * relation is stored in its database's "default" tablespace (as
65  * identified by pg_database.dattablespace).  However this shorthand
66  * is NOT allowed in RelFileNode structs --- the real tablespace ID
67  * must be supplied when setting spcNode.
68  *
69  * Note: in pg_class, relfilenode can be zero to denote that the relation
70  * is a "mapped" relation, whose current true filenode number is available
71  * from relmapper.c.  Again, this case is NOT allowed in RelFileNodes.
72  *
73  * Note: various places use RelFileNode in hashtable keys.  Therefore,
74  * there *must not* be any unused padding bytes in this struct.  That
75  * should be safe as long as all the fields are of type Oid.
76  */
77 typedef struct RelFileNode
78 {
79         Oid                     spcNode;                /* tablespace */
80         Oid                     dbNode;                 /* database */
81         Oid                     relNode;                /* relation */
82 } RelFileNode;
83
84 /*
85  * Augmenting a relfilenode with the backend ID provides all the information
86  * we need to locate the physical storage.  The backend ID is InvalidBackendId
87  * for regular relations (those accessible to more than one backend), or the
88  * owning backend's ID for backend-local relations.  Backend-local relations
89  * are always transient and removed in case of a database crash; they are
90  * never WAL-logged or fsync'd.
91  */
92 typedef struct RelFileNodeBackend
93 {
94         RelFileNode node;
95         BackendId       backend;
96 } RelFileNodeBackend;
97
98 #define RelFileNodeBackendIsTemp(rnode) \
99         ((rnode).backend != InvalidBackendId)
100
101 /*
102  * Note: RelFileNodeEquals and RelFileNodeBackendEquals compare relNode first
103  * since that is most likely to be different in two unequal RelFileNodes.  It
104  * is probably redundant to compare spcNode if the other fields are found equal,
105  * but do it anyway to be sure.  Likewise for checking the backend ID in
106  * RelFileNodeBackendEquals.
107  */
108 #define RelFileNodeEquals(node1, node2) \
109         ((node1).relNode == (node2).relNode && \
110          (node1).dbNode == (node2).dbNode && \
111          (node1).spcNode == (node2).spcNode)
112
113 #define RelFileNodeBackendEquals(node1, node2) \
114         ((node1).node.relNode == (node2).node.relNode && \
115          (node1).node.dbNode == (node2).node.dbNode && \
116          (node1).backend == (node2).backend && \
117          (node1).node.spcNode == (node2).node.spcNode)
118
119 #endif   /* RELFILENODE_H */