1 /*-------------------------------------------------------------------------
4 * Physical access information for relations.
7 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/relfilenode.h
12 *-------------------------------------------------------------------------
17 #include "storage/backendid.h"
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.
25 typedef enum ForkNumber
27 InvalidForkNumber = -1,
30 VISIBILITYMAP_FORKNUM,
34 * NOTE: if you add a new fork, change MAX_FORKNUM below and update the
35 * forkNames array in src/common/relpath.c
39 #define MAX_FORKNUM INIT_FORKNUM
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.
48 * spcNode identifies the tablespace of the relation. It corresponds to
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.
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.
60 * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is
61 * zero. We support shared relations only in the "global" tablespace.
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.
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.
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.
77 typedef struct RelFileNode
79 Oid spcNode; /* tablespace */
80 Oid dbNode; /* database */
81 Oid relNode; /* relation */
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.
92 typedef struct RelFileNodeBackend
98 #define RelFileNodeBackendIsTemp(rnode) \
99 ((rnode).backend != InvalidBackendId)
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.
108 #define RelFileNodeEquals(node1, node2) \
109 ((node1).relNode == (node2).relNode && \
110 (node1).dbNode == (node2).dbNode && \
111 (node1).spcNode == (node2).spcNode)
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)
119 #endif /* RELFILENODE_H */