1 /*-------------------------------------------------------------------------
4 * Physical access information for relations.
7 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/storage/relfilenode.h
12 *-------------------------------------------------------------------------
17 #include "common/relpath.h"
18 #include "storage/backendid.h"
21 * RelFileNode must provide all that we need to know to physically access
22 * a relation, with the exception of the backend ID, which can be provided
23 * separately. Note, however, that a "physical" relation is comprised of
24 * multiple files on the filesystem, as each fork is stored as a separate
25 * file, and each fork can be divided into multiple segments. See md.c.
27 * spcNode identifies the tablespace of the relation. It corresponds to
30 * dbNode identifies the database of the relation. It is zero for
31 * "shared" relations (those common to all databases of a cluster).
32 * Nonzero dbNode values correspond to pg_database.oid.
34 * relNode identifies the specific relation. relNode corresponds to
35 * pg_class.relfilenode (NOT pg_class.oid, because we need to be able
36 * to assign new physical files to relations in some situations).
37 * Notice that relNode is only unique within a database in a particular
40 * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is
41 * zero. We support shared relations only in the "global" tablespace.
43 * Note: in pg_class we allow reltablespace == 0 to denote that the
44 * relation is stored in its database's "default" tablespace (as
45 * identified by pg_database.dattablespace). However this shorthand
46 * is NOT allowed in RelFileNode structs --- the real tablespace ID
47 * must be supplied when setting spcNode.
49 * Note: in pg_class, relfilenode can be zero to denote that the relation
50 * is a "mapped" relation, whose current true filenode number is available
51 * from relmapper.c. Again, this case is NOT allowed in RelFileNodes.
53 * Note: various places use RelFileNode in hashtable keys. Therefore,
54 * there *must not* be any unused padding bytes in this struct. That
55 * should be safe as long as all the fields are of type Oid.
57 typedef struct RelFileNode
59 Oid spcNode
; /* tablespace */
60 Oid dbNode
; /* database */
61 Oid relNode
; /* relation */
65 * Augmenting a relfilenode with the backend ID provides all the information
66 * we need to locate the physical storage. The backend ID is InvalidBackendId
67 * for regular relations (those accessible to more than one backend), or the
68 * owning backend's ID for backend-local relations. Backend-local relations
69 * are always transient and removed in case of a database crash; they are
70 * never WAL-logged or fsync'd.
72 typedef struct RelFileNodeBackend
78 #define RelFileNodeBackendIsTemp(rnode) \
79 ((rnode).backend != InvalidBackendId)
82 * Note: RelFileNodeEquals and RelFileNodeBackendEquals compare relNode first
83 * since that is most likely to be different in two unequal RelFileNodes. It
84 * is probably redundant to compare spcNode if the other fields are found equal,
85 * but do it anyway to be sure. Likewise for checking the backend ID in
86 * RelFileNodeBackendEquals.
88 #define RelFileNodeEquals(node1, node2) \
89 ((node1).relNode == (node2).relNode && \
90 (node1).dbNode == (node2).dbNode && \
91 (node1).spcNode == (node2).spcNode)
93 #define RelFileNodeBackendEquals(node1, node2) \
94 ((node1).node.relNode == (node2).node.relNode && \
95 (node1).node.dbNode == (node2).node.dbNode && \
96 (node1).backend == (node2).backend && \
97 (node1).node.spcNode == (node2).node.spcNode)
99 #endif /* RELFILENODE_H */