1 /*-------------------------------------------------------------------------
2  *
3  * relfilenode.h
4  *	  Physical access information for relations.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, 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 "common/relpath.h"
18 #include "storage/backendid.h"
19 
20 /*
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.
26  *
27  * spcNode identifies the tablespace of the relation.  It corresponds to
28  * pg_tablespace.oid.
29  *
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.
33  *
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
38  * tablespace.
39  *
40  * Note: spcNode must be GLOBALTABLESPACE_OID if and only if dbNode is
41  * zero.  We support shared relations only in the "global" tablespace.
42  *
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.
48  *
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.
52  *
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.
56  */
57 typedef struct RelFileNode
58 {
59 	Oid			spcNode;		/* tablespace */
60 	Oid			dbNode;			/* database */
61 	Oid			relNode;		/* relation */
62 } RelFileNode;
63 
64 /*
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.
71  */
72 typedef struct RelFileNodeBackend
73 {
74 	RelFileNode node;
75 	BackendId	backend;
76 } RelFileNodeBackend;
77 
78 #define RelFileNodeBackendIsTemp(rnode) \
79 	((rnode).backend != InvalidBackendId)
80 
81 /*
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.
87  */
88 #define RelFileNodeEquals(node1, node2) \
89 	((node1).relNode == (node2).relNode && \
90 	 (node1).dbNode == (node2).dbNode && \
91 	 (node1).spcNode == (node2).spcNode)
92 
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)
98 
99 #endif							/* RELFILENODE_H */
100