PostgreSQL Source Code  git master
relfilelocator.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * relfilelocator.h
4  * Physical access information for relations.
5  *
6  *
7  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/storage/relfilelocator.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef RELFILELOCATOR_H
15 #define RELFILELOCATOR_H
16 
17 #include "common/relpath.h"
18 #include "storage/backendid.h"
19 
20 /*
21  * RelFileLocator 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  * spcOid identifies the tablespace of the relation. It corresponds to
28  * pg_tablespace.oid.
29  *
30  * dbOid identifies the database of the relation. It is zero for
31  * "shared" relations (those common to all databases of a cluster).
32  * Nonzero dbOid values correspond to pg_database.oid.
33  *
34  * relNumber identifies the specific relation. relNumber 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 relNumber is only unique within a database in a particular
38  * tablespace.
39  *
40  * Note: spcOid must be GLOBALTABLESPACE_OID if and only if dbOid 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 RelFileLocator structs --- the real tablespace ID
47  * must be supplied when setting spcOid.
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 RelFileLocators.
52  *
53  * Note: various places use RelFileLocator 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 RelFileLocator
58 {
59  Oid spcOid; /* tablespace */
60  Oid dbOid; /* database */
61  RelFileNumber relNumber; /* relation */
63 
64 /*
65  * Augmenting a relfilelocator 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 RelFileLocatorBackend
73 {
77 
78 #define RelFileLocatorBackendIsTemp(rlocator) \
79  ((rlocator).backend != InvalidBackendId)
80 
81 /*
82  * Note: RelFileLocatorEquals and RelFileLocatorBackendEquals compare relNumber
83  * first since that is most likely to be different in two unequal
84  * RelFileLocators. It is probably redundant to compare spcOid if the other
85  * fields are found equal, but do it anyway to be sure. Likewise for checking
86  * the backend ID in RelFileLocatorBackendEquals.
87  */
88 #define RelFileLocatorEquals(locator1, locator2) \
89  ((locator1).relNumber == (locator2).relNumber && \
90  (locator1).dbOid == (locator2).dbOid && \
91  (locator1).spcOid == (locator2).spcOid)
92 
93 #define RelFileLocatorBackendEquals(locator1, locator2) \
94  ((locator1).locator.relNumber == (locator2).locator.relNumber && \
95  (locator1).locator.dbOid == (locator2).locator.dbOid && \
96  (locator1).backend == (locator2).backend && \
97  (locator1).locator.spcOid == (locator2).locator.spcOid)
98 
99 #endif /* RELFILELOCATOR_H */
int BackendId
Definition: backendid.h:21
unsigned int Oid
Definition: postgres_ext.h:31
struct RelFileLocator RelFileLocator
struct RelFileLocatorBackend RelFileLocatorBackend
Oid RelFileNumber
Definition: relpath.h:25
RelFileLocator locator
RelFileNumber relNumber