Skip to content

Commit 2fe4167

Browse files
committed
Fix search_path cache initialization.
The cache needs to be available very early, so don't rely on InitializeSearchPath() to initialize the it. Reported-by: Murat Efendioğlu Discussion: https://postgr.es/m/CACbCzujQ4zS8MM1bx-==+tr+D3Hk5G1cjN4XkUQ+Q=cEpwhzqg@mail.gmail.com Backpatch-through: 17
1 parent a8b2402 commit 2fe4167

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/backend/catalog/namespace.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,32 @@ static SearchPathCacheEntry *LastSearchPathCacheEntry = NULL;
305305
static void
306306
spcache_init(void)
307307
{
308-
Assert(SearchPathCacheContext);
309-
310308
if (SearchPathCache && searchPathCacheValid &&
311309
SearchPathCache->members < SPCACHE_RESET_THRESHOLD)
312310
return;
313311

314-
/* make sure we don't leave dangling pointers if nsphash_create fails */
312+
searchPathCacheValid = false;
313+
baseSearchPathValid = false;
314+
315+
/*
316+
* Make sure we don't leave dangling pointers if a failure happens during
317+
* initialization.
318+
*/
315319
SearchPathCache = NULL;
316320
LastSearchPathCacheEntry = NULL;
317321

318-
MemoryContextReset(SearchPathCacheContext);
322+
if (SearchPathCacheContext == NULL)
323+
{
324+
/* Make the context we'll keep search path cache hashtable in */
325+
SearchPathCacheContext = AllocSetContextCreate(TopMemoryContext,
326+
"search_path processing cache",
327+
ALLOCSET_DEFAULT_SIZES);
328+
}
329+
else
330+
{
331+
MemoryContextReset(SearchPathCacheContext);
332+
}
333+
319334
/* arbitrary initial starting size of 16 elements */
320335
SearchPathCache = nsphash_create(SearchPathCacheContext, 16, NULL);
321336
searchPathCacheValid = true;
@@ -4742,11 +4757,6 @@ InitializeSearchPath(void)
47424757
}
47434758
else
47444759
{
4745-
/* Make the context we'll keep search path cache hashtable in */
4746-
SearchPathCacheContext = AllocSetContextCreate(TopMemoryContext,
4747-
"search_path processing cache",
4748-
ALLOCSET_DEFAULT_SIZES);
4749-
47504760
/*
47514761
* In normal mode, arrange for a callback on any syscache invalidation
47524762
* that will affect the search_path cache.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy