2
0

relfilenode.h 3.8 KB

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