diff options
| author | Tom Lane | 2021-07-15 15:41:47 +0000 |
|---|---|---|
| committer | Tom Lane | 2021-07-15 15:41:47 +0000 |
| commit | a49d081235997c67e8aab7a523b17e8d1cb93184 (patch) | |
| tree | 4bf81347757488fc1ab5c651dc4f3ab0eb1b8a87 /src/include | |
| parent | e529b2dc37ac80ccebd76cdbb14966d3b40819c9 (diff) | |
Replace explicit PIN entries in pg_depend with an OID range test.
As of v14, pg_depend contains almost 7000 "pin" entries recording
the OIDs of built-in objects. This is a fair amount of bloat for
every database, and it adds time to pg_depend lookups as well as
initdb. We can get rid of all of those entries in favor of an OID
range check, i.e. "OIDs below FirstUnpinnedObjectId are pinned".
(template1 and the public schema are exceptions. Those exceptions
are now wired into IsPinnedObject() instead of initdb's code for
filling pg_depend, but it's the same amount of cruft either way.)
The contents of pg_shdepend are modified likewise.
Discussion: https://postgr.es/m/3737988.1618451008@sss.pgh.pa.us
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/access/transam.h | 16 | ||||
| -rw-r--r-- | src/include/catalog/catalog.h | 2 | ||||
| -rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
| -rw-r--r-- | src/include/catalog/dependency.h | 18 | ||||
| -rw-r--r-- | src/include/catalog/pg_depend.h | 11 | ||||
| -rw-r--r-- | src/include/catalog/pg_proc.dat | 4 | ||||
| -rw-r--r-- | src/include/catalog/pg_shdepend.h | 12 |
7 files changed, 34 insertions, 31 deletions
diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 2fe8a591105..d22de19c94c 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -165,10 +165,14 @@ FullTransactionIdAdvance(FullTransactionId *dest) * when the .dat files in src/include/catalog/ do not specify an OID * for a catalog entry that requires one. Note that genbki.pl assigns * these OIDs independently in each catalog, so they're not guaranteed - * to be globally unique. + * to be globally unique. Furthermore, the bootstrap backend and + * initdb's post-bootstrap processing can also assign OIDs in this range. + * The normal OID-generation logic takes care of any OID conflicts that + * might arise from that. * - * OIDS 12000-16383 are reserved for assignment during initdb - * using the OID generator. (We start the generator at 12000.) + * OIDs 12000-16383 are reserved for unpinned objects created by initdb's + * post-bootstrap processing. initdb forces the OID generator up to + * 12000 as soon as it's made the pinned objects it's responsible for. * * OIDs beginning at 16384 are assigned from the OID generator * during normal multiuser operation. (We force the generator up to @@ -184,11 +188,12 @@ FullTransactionIdAdvance(FullTransactionId *dest) * * NOTE: if the OID generator wraps around, we skip over OIDs 0-16383 * and resume with 16384. This minimizes the odds of OID conflict, by not - * reassigning OIDs that might have been assigned during initdb. + * reassigning OIDs that might have been assigned during initdb. Critically, + * it also ensures that no user-created object will be considered pinned. * ---------- */ #define FirstGenbkiObjectId 10000 -#define FirstBootstrapObjectId 12000 +#define FirstUnpinnedObjectId 12000 #define FirstNormalObjectId 16384 /* @@ -289,6 +294,7 @@ extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, extern void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid); extern bool ForceTransactionIdLimitUpdate(void); extern Oid GetNewObjectId(void); +extern void StopGeneratingPinnedObjectIds(void); #ifdef USE_ASSERT_CHECKING extern void AssertTransactionIdInAllowableRange(TransactionId xid); diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index f247be50b4d..ef2e88fe454 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -34,6 +34,8 @@ extern bool IsReservedName(const char *name); extern bool IsSharedRelation(Oid relationId); +extern bool IsPinnedObject(Oid classId, Oid objectId); + extern Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn); extern Oid GetNewRelFileNode(Oid reltablespace, Relation pg_class, diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index f2ecafa1daa..358dfdbbd30 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202107141 +#define CATALOG_VERSION_NO 202107151 #endif diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h index fd44081e741..2885f35ccd2 100644 --- a/src/include/catalog/dependency.h +++ b/src/include/catalog/dependency.h @@ -36,8 +36,7 @@ typedef enum DependencyType DEPENDENCY_PARTITION_PRI = 'P', DEPENDENCY_PARTITION_SEC = 'S', DEPENDENCY_EXTENSION = 'e', - DEPENDENCY_AUTO_EXTENSION = 'x', - DEPENDENCY_PIN = 'p' + DEPENDENCY_AUTO_EXTENSION = 'x' } DependencyType; /* @@ -47,27 +46,21 @@ typedef enum DependencyType * unless the dependent object is dropped at the same time. There are some * additional rules however: * - * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object -- - * rather, the referenced object is an essential part of the system. This - * applies to the initdb-created superuser. Entries of this type are only - * created by initdb; objects in this category don't need further pg_shdepend - * entries if more objects come to depend on them. - * - * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is + * (a) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is * the role owning the dependent object. The referenced object must be * a pg_authid entry. * - * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is + * (b) a SHARED_DEPENDENCY_ACL entry means that the referenced object is * a role mentioned in the ACL field of the dependent object. The referenced * object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not * created for the owner of an object; hence two objects may be linked by * one or the other, but not both, of these dependency types.) * - * (d) a SHARED_DEPENDENCY_POLICY entry means that the referenced object is + * (c) a SHARED_DEPENDENCY_POLICY entry means that the referenced object is * a role mentioned in a policy object. The referenced object must be a * pg_authid entry. * - * (e) a SHARED_DEPENDENCY_TABLESPACE entry means that the referenced + * (d) a SHARED_DEPENDENCY_TABLESPACE entry means that the referenced * object is a tablespace mentioned in a relation without storage. The * referenced object must be a pg_tablespace entry. (Relations that have * storage don't need this: they are protected by the existence of a physical @@ -78,7 +71,6 @@ typedef enum DependencyType */ typedef enum SharedDependencyType { - SHARED_DEPENDENCY_PIN = 'p', SHARED_DEPENDENCY_OWNER = 'o', SHARED_DEPENDENCY_ACL = 'a', SHARED_DEPENDENCY_POLICY = 'r', diff --git a/src/include/catalog/pg_depend.h b/src/include/catalog/pg_depend.h index f41ae3add12..90a5699b6e4 100644 --- a/src/include/catalog/pg_depend.h +++ b/src/include/catalog/pg_depend.h @@ -4,8 +4,9 @@ * definition of the "dependency" system catalog (pg_depend) * * pg_depend has no preloaded contents, so there is no pg_depend.dat - * file; system-defined dependencies are loaded into it during a late stage - * of the initdb process. + * file; dependencies for system-defined objects are loaded into it + * on-the-fly during initdb. Most built-in objects are pinned anyway, + * and hence need no explicit entries in pg_depend. * * NOTE: we do not represent all possible dependency pairs in pg_depend; * for example, there's not much value in creating an explicit dependency @@ -42,11 +43,9 @@ CATALOG(pg_depend,2608,DependRelationId) { /* * Identification of the dependent (referencing) object. - * - * These fields are all zeroes for a DEPENDENCY_PIN entry. */ - Oid classid BKI_LOOKUP_OPT(pg_class); /* OID of table containing - * object */ + Oid classid BKI_LOOKUP(pg_class); /* OID of table containing + * object */ Oid objid; /* OID of object itself */ int32 objsubid; /* column number, or 0 if not used */ diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index fde251fa4f3..8bf9d704b70 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -3295,6 +3295,10 @@ proname => 'pg_nextoid', provolatile => 'v', proparallel => 'u', prorettype => 'oid', proargtypes => 'regclass name regclass', prosrc => 'pg_nextoid' }, +{ oid => '8922', descr => 'stop making pinned objects during initdb', + proname => 'pg_stop_making_pinned_objects', provolatile => 'v', + proparallel => 'u', prorettype => 'void', proargtypes => '', + prosrc => 'pg_stop_making_pinned_objects' }, { oid => '1579', descr => 'I/O', proname => 'varbit_in', prorettype => 'varbit', diff --git a/src/include/catalog/pg_shdepend.h b/src/include/catalog/pg_shdepend.h index c77452c5846..06616b90865 100644 --- a/src/include/catalog/pg_shdepend.h +++ b/src/include/catalog/pg_shdepend.h @@ -4,8 +4,9 @@ * definition of the "shared dependency" system catalog (pg_shdepend) * * pg_shdepend has no preloaded contents, so there is no pg_shdepend.dat - * file; system-defined dependencies are loaded into it during a late stage - * of the initdb process. + * file; dependencies for system-defined objects are loaded into it + * on-the-fly during initdb. Most built-in objects are pinned anyway, + * and hence need no explicit entries in pg_shdepend. * * NOTE: we do not represent all possible dependency pairs in pg_shdepend; * for example, there's not much value in creating an explicit dependency @@ -39,13 +40,12 @@ CATALOG(pg_shdepend,1214,SharedDependRelationId) BKI_SHARED_RELATION /* * Identification of the dependent (referencing) object. * - * These fields are all zeroes for a DEPENDENCY_PIN entry. Also, dbid can - * be zero to denote a shared object. + * Note that dbid can be zero to denote a shared object. */ Oid dbid BKI_LOOKUP_OPT(pg_database); /* OID of database * containing object */ - Oid classid BKI_LOOKUP_OPT(pg_class); /* OID of table containing - * object */ + Oid classid BKI_LOOKUP(pg_class); /* OID of table containing + * object */ Oid objid; /* OID of object itself */ int32 objsubid; /* column number, or 0 if not used */ |
