From 4c2736519f0250b3c4396b04b34e3001ef7adf8a Mon Sep 17 00:00:00 2001
From: David Geier <geidav.pg@gmail.com>
Date: Fri, 18 Sep 2026 12:52:47 +0200
Subject: [PATCH v3 1/8] Remove unnecessary CacheMemoryContext existence checks

RelationCacheInitialize() is called from InitPostgres() before any
catalog or relcache access can happen, and it creates
CacheMemoryContext.  Since that context is a child of TopMemoryContext
and is never deleted or reset, it is guaranteed to exist by the time
any of these code paths run.  The remaining check in
RelationCacheInitialize() itself is the one that actually creates it.
---
 src/backend/utils/cache/relcache.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index d8f04a05309..dc42f2c4c1f 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1676,10 +1676,6 @@ LookupOpclassInfo(Oid operatorClassOid,
 		/* First time through: initialize the opclass cache */
 		HASHCTL		ctl;
 
-		/* Also make sure CacheMemoryContext exists */
-		if (!CacheMemoryContext)
-			CreateCacheMemoryContext();
-
 		ctl.keysize = sizeof(Oid);
 		ctl.entrysize = sizeof(OpClassCacheEnt);
 		OpClassCache = hash_create("Operator class cache", 64,
@@ -3565,9 +3561,6 @@ RelationBuildLocalRelation(const char *relname,
 	/*
 	 * switch to the cache context to create the relcache entry.
 	 */
-	if (!CacheMemoryContext)
-		CreateCacheMemoryContext();
-
 	oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
 
 	/*
-- 
2.53.0

