Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae6bc39

Browse files
committed
Minor fixes for search path cache code.
Avoid leaving a dangling pointer in the unlikely event thatnsphash_create fails. Improve comments, and fix formatting byadding typedefs.list entries.Discussion:https://postgr.es/m/3972900.1704145107@sss.pgh.pa.us
1 parent371b07e commitae6bc39

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

‎src/backend/catalog/namespace.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,19 @@ static OidnamespaceUser = InvalidOid;
156156

157157
/* The above four values are valid only if baseSearchPathValid */
158158
staticboolbaseSearchPathValid= true;
159+
160+
/*
161+
* Storage for search path cache. Clear searchPathCacheValid as a simple
162+
* way to invalidate *all* the cache entries, not just the active one.
163+
*/
159164
staticboolsearchPathCacheValid= false;
160165
staticMemoryContextSearchPathCacheContext=NULL;
161166

162167
typedefstructSearchPathCacheKey
163168
{
164169
constchar*searchPath;
165170
Oidroleid;
166-
}SearchPathCacheKey;
171+
}SearchPathCacheKey;
167172

168173
typedefstructSearchPathCacheEntry
169174
{
@@ -176,7 +181,7 @@ typedef struct SearchPathCacheEntry
176181

177182
/* needed for simplehash */
178183
charstatus;
179-
}SearchPathCacheEntry;
184+
}SearchPathCacheEntry;
180185

181186
/*
182187
* myTempNamespace is InvalidOid until and unless a TEMP namespace is set up
@@ -281,8 +286,8 @@ spcachekey_equal(SearchPathCacheKey a, SearchPathCacheKey b)
281286
*/
282287
#defineSPCACHE_RESET_THRESHOLD256
283288

284-
staticnsphash_hash*SearchPathCache=NULL;
285-
staticSearchPathCacheEntry*LastSearchPathCacheEntry=NULL;
289+
staticnsphash_hash*SearchPathCache=NULL;
290+
staticSearchPathCacheEntry*LastSearchPathCacheEntry=NULL;
286291

287292
/*
288293
* Create or reset search_path cache as necessary.
@@ -296,8 +301,11 @@ spcache_init(void)
296301
SearchPathCache->members<SPCACHE_RESET_THRESHOLD)
297302
return;
298303

299-
MemoryContextReset(SearchPathCacheContext);
304+
/* make sure we don't leave dangling pointers if nsphash_create fails */
305+
SearchPathCache=NULL;
300306
LastSearchPathCacheEntry=NULL;
307+
308+
MemoryContextReset(SearchPathCacheContext);
301309
/* arbitrary initial starting size of 16 elements */
302310
SearchPathCache=nsphash_create(SearchPathCacheContext,16,NULL);
303311
searchPathCacheValid= true;
@@ -325,8 +333,8 @@ spcache_lookup(const char *searchPath, Oid roleid)
325333
};
326334

327335
entry=nsphash_lookup(SearchPathCache,cachekey);
328-
329-
LastSearchPathCacheEntry=entry;
336+
if (entry)
337+
LastSearchPathCacheEntry=entry;
330338
returnentry;
331339
}
332340
}
@@ -4267,7 +4275,7 @@ recomputeNamespacePath(void)
42674275
{
42684276
Oidroleid=GetUserId();
42694277
boolpathChanged;
4270-
constSearchPathCacheEntry*entry;
4278+
constSearchPathCacheEntry*entry;
42714279

42724280
/* Do nothing if path is already valid. */
42734281
if (baseSearchPathValid&&namespaceUser==roleid)
@@ -4635,9 +4643,7 @@ check_search_path(char **newval, void **extra, GucSource source)
46354643
* schemas that don't exist; and often, we are not inside a transaction
46364644
* here and so can't consult the system catalogs anyway. So now, the only
46374645
* requirement is syntactic validity of the identifier list.
4638-
*/
4639-
4640-
/*
4646+
*
46414647
* Checking only the syntactic validity also allows us to use the search
46424648
* path cache (if available) to avoid calling SplitIdentifierString() on
46434649
* the same string repeatedly.
@@ -4667,19 +4673,10 @@ check_search_path(char **newval, void **extra, GucSource source)
46674673
list_free(namelist);
46684674
return false;
46694675
}
4670-
4671-
/*
4672-
* We used to try to check that the named schemas exist, but there are
4673-
* many valid use-cases for having search_path settings that include
4674-
* schemas that don't exist; and often, we are not inside a transaction
4675-
* here and so can't consult the system catalogs anyway. So now, the only
4676-
* requirement is syntactic validity of the identifier list.
4677-
*/
4678-
46794676
pfree(rawname);
46804677
list_free(namelist);
46814678

4682-
/* create empty cache entry */
4679+
/*OK tocreate empty cache entry */
46834680
if (use_cache)
46844681
(void)spcache_insert(searchPath,roleid);
46854682

@@ -4732,8 +4729,9 @@ InitializeSearchPath(void)
47324729
}
47334730
else
47344731
{
4735-
SearchPathCacheContext=AllocSetContextCreate(
4736-
TopMemoryContext,"search_path processing cache",
4732+
/* Make the context we'll keep search path cache hashtable in */
4733+
SearchPathCacheContext=AllocSetContextCreate(TopMemoryContext,
4734+
"search_path processing cache",
47374735
ALLOCSET_DEFAULT_SIZES);
47384736

47394737
/*

‎src/tools/pgindent/typedefs.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,8 @@ ScanState
24802480
ScanTypeControl
24812481
ScannerCallbackState
24822482
SchemaQuery
2483+
SearchPathCacheEntry
2484+
SearchPathCacheKey
24832485
SearchPathMatcher
24842486
SecBuffer
24852487
SecBufferDesc
@@ -3515,6 +3517,7 @@ needs_fmgr_hook_type
35153517
network_sortsupport_state
35163518
nodeitem
35173519
normal_rand_fctx
3520+
nsphash_hash
35183521
ntile_context
35193522
numeric
35203523
object_access_hook_type

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp