Rename OverrideSearchPath to SearchPathMatcher.

The previous commit removed the "override" APIs.  Surviving APIs facilitate
plancache.c to snapshot search_path and test whether the current value equals
a remembered snapshot.

Aleksander Alekseev.  Reported by Alexander Lakhin and Noah Misch.

Discussion: https://postgr.es/m/8ffb4650-52c4-6a81-38fc-8f99be981130@gmail.com
This commit is contained in:
Noah Misch 2023-07-31 17:04:47 -07:00
parent 7c5c4e1c03
commit d3a38318ac
5 changed files with 26 additions and 26 deletions

View File

@ -3374,16 +3374,16 @@ SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
/* /*
* GetOverrideSearchPath - fetch current search path definition. * GetSearchPathMatcher - fetch current search path definition.
* *
* The result structure is allocated in the specified memory context * The result structure is allocated in the specified memory context
* (which might or might not be equal to CurrentMemoryContext); but any * (which might or might not be equal to CurrentMemoryContext); but any
* junk created by revalidation calculations will be in CurrentMemoryContext. * junk created by revalidation calculations will be in CurrentMemoryContext.
*/ */
OverrideSearchPath * SearchPathMatcher *
GetOverrideSearchPath(MemoryContext context) GetSearchPathMatcher(MemoryContext context)
{ {
OverrideSearchPath *result; SearchPathMatcher *result;
List *schemas; List *schemas;
MemoryContext oldcxt; MemoryContext oldcxt;
@ -3391,7 +3391,7 @@ GetOverrideSearchPath(MemoryContext context)
oldcxt = MemoryContextSwitchTo(context); oldcxt = MemoryContextSwitchTo(context);
result = (OverrideSearchPath *) palloc0(sizeof(OverrideSearchPath)); result = (SearchPathMatcher *) palloc0(sizeof(SearchPathMatcher));
schemas = list_copy(activeSearchPath); schemas = list_copy(activeSearchPath);
while (schemas && linitial_oid(schemas) != activeCreationNamespace) while (schemas && linitial_oid(schemas) != activeCreationNamespace)
{ {
@ -3413,16 +3413,16 @@ GetOverrideSearchPath(MemoryContext context)
} }
/* /*
* CopyOverrideSearchPath - copy the specified OverrideSearchPath. * CopySearchPathMatcher - copy the specified SearchPathMatcher.
* *
* The result structure is allocated in CurrentMemoryContext. * The result structure is allocated in CurrentMemoryContext.
*/ */
OverrideSearchPath * SearchPathMatcher *
CopyOverrideSearchPath(OverrideSearchPath *path) CopySearchPathMatcher(SearchPathMatcher *path)
{ {
OverrideSearchPath *result; SearchPathMatcher *result;
result = (OverrideSearchPath *) palloc(sizeof(OverrideSearchPath)); result = (SearchPathMatcher *) palloc(sizeof(SearchPathMatcher));
result->schemas = list_copy(path->schemas); result->schemas = list_copy(path->schemas);
result->addCatalog = path->addCatalog; result->addCatalog = path->addCatalog;
result->addTemp = path->addTemp; result->addTemp = path->addTemp;
@ -3432,7 +3432,7 @@ CopyOverrideSearchPath(OverrideSearchPath *path)
} }
/* /*
* OverrideSearchPathMatchesCurrent - does path match current setting? * SearchPathMatchesCurrentEnvironment - does path match current environment?
* *
* This is tested over and over in some common code paths, and in the typical * This is tested over and over in some common code paths, and in the typical
* scenario where the active search path seldom changes, it'll always succeed. * scenario where the active search path seldom changes, it'll always succeed.
@ -3440,7 +3440,7 @@ CopyOverrideSearchPath(OverrideSearchPath *path)
* whenever the active search path changes. * whenever the active search path changes.
*/ */
bool bool
OverrideSearchPathMatchesCurrent(OverrideSearchPath *path) SearchPathMatchesCurrentEnvironment(SearchPathMatcher *path)
{ {
ListCell *lc, ListCell *lc,
*lcp; *lcp;

View File

@ -407,7 +407,7 @@ CompleteCachedPlan(CachedPlanSource *plansource,
* one-shot plans; and we *must* skip this for transaction control * one-shot plans; and we *must* skip this for transaction control
* commands, because this could result in catalog accesses. * commands, because this could result in catalog accesses.
*/ */
plansource->search_path = GetOverrideSearchPath(querytree_context); plansource->search_path = GetSearchPathMatcher(querytree_context);
} }
/* /*
@ -586,7 +586,7 @@ RevalidateCachedQuery(CachedPlanSource *plansource,
if (plansource->is_valid) if (plansource->is_valid)
{ {
Assert(plansource->search_path != NULL); Assert(plansource->search_path != NULL);
if (!OverrideSearchPathMatchesCurrent(plansource->search_path)) if (!SearchPathMatchesCurrentEnvironment(plansource->search_path))
{ {
/* Invalidate the querytree and generic plan */ /* Invalidate the querytree and generic plan */
plansource->is_valid = false; plansource->is_valid = false;
@ -759,7 +759,7 @@ RevalidateCachedQuery(CachedPlanSource *plansource,
* not generate much extra cruft either, since almost certainly the path * not generate much extra cruft either, since almost certainly the path
* is already valid.) * is already valid.)
*/ */
plansource->search_path = GetOverrideSearchPath(querytree_context); plansource->search_path = GetSearchPathMatcher(querytree_context);
MemoryContextSwitchTo(oldcxt); MemoryContextSwitchTo(oldcxt);
@ -1326,7 +1326,7 @@ CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource,
Assert(plan->is_valid); Assert(plan->is_valid);
Assert(plan == plansource->gplan); Assert(plan == plansource->gplan);
Assert(plansource->search_path != NULL); Assert(plansource->search_path != NULL);
Assert(OverrideSearchPathMatchesCurrent(plansource->search_path)); Assert(SearchPathMatchesCurrentEnvironment(plansource->search_path));
/* We don't support oneshot plans here. */ /* We don't support oneshot plans here. */
if (plansource->is_oneshot) if (plansource->is_oneshot)
@ -1449,7 +1449,7 @@ CachedPlanIsSimplyValid(CachedPlanSource *plansource, CachedPlan *plan,
/* Is the search_path still the same as when we made it? */ /* Is the search_path still the same as when we made it? */
Assert(plansource->search_path != NULL); Assert(plansource->search_path != NULL);
if (!OverrideSearchPathMatchesCurrent(plansource->search_path)) if (!SearchPathMatchesCurrentEnvironment(plansource->search_path))
return false; return false;
/* It's still good. Bump refcount if requested. */ /* It's still good. Bump refcount if requested. */
@ -1565,7 +1565,7 @@ CopyCachedPlan(CachedPlanSource *plansource)
newsource->relationOids = copyObject(plansource->relationOids); newsource->relationOids = copyObject(plansource->relationOids);
newsource->invalItems = copyObject(plansource->invalItems); newsource->invalItems = copyObject(plansource->invalItems);
if (plansource->search_path) if (plansource->search_path)
newsource->search_path = CopyOverrideSearchPath(plansource->search_path); newsource->search_path = CopySearchPathMatcher(plansource->search_path);
newsource->query_context = querytree_context; newsource->query_context = querytree_context;
newsource->rewriteRoleId = plansource->rewriteRoleId; newsource->rewriteRoleId = plansource->rewriteRoleId;
newsource->rewriteRowSecurity = plansource->rewriteRowSecurity; newsource->rewriteRowSecurity = plansource->rewriteRowSecurity;

View File

@ -49,19 +49,19 @@ typedef enum TempNamespaceStatus
} TempNamespaceStatus; } TempNamespaceStatus;
/* /*
* Structure for xxxOverrideSearchPath functions * Structure for xxxSearchPathMatcher functions
* *
* The generation counter is private to namespace.c and shouldn't be touched * The generation counter is private to namespace.c and shouldn't be touched
* by other code. It can be initialized to zero if necessary (that means * by other code. It can be initialized to zero if necessary (that means
* "not known equal to the current active path"). * "not known equal to the current active path").
*/ */
typedef struct OverrideSearchPath typedef struct SearchPathMatcher
{ {
List *schemas; /* OIDs of explicitly named schemas */ List *schemas; /* OIDs of explicitly named schemas */
bool addCatalog; /* implicitly prepend pg_catalog? */ bool addCatalog; /* implicitly prepend pg_catalog? */
bool addTemp; /* implicitly prepend temp schema? */ bool addTemp; /* implicitly prepend temp schema? */
uint64 generation; /* for quick detection of equality to active */ uint64 generation; /* for quick detection of equality to active */
} OverrideSearchPath; } SearchPathMatcher;
/* /*
* Option flag bits for RangeVarGetRelidExtended(). * Option flag bits for RangeVarGetRelidExtended().
@ -164,9 +164,9 @@ extern void SetTempNamespaceState(Oid tempNamespaceId,
Oid tempToastNamespaceId); Oid tempToastNamespaceId);
extern void ResetTempTableNamespace(void); extern void ResetTempTableNamespace(void);
extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context); extern SearchPathMatcher *GetSearchPathMatcher(MemoryContext context);
extern OverrideSearchPath *CopyOverrideSearchPath(OverrideSearchPath *path); extern SearchPathMatcher *CopySearchPathMatcher(SearchPathMatcher *path);
extern bool OverrideSearchPathMatchesCurrent(OverrideSearchPath *path); extern bool SearchPathMatchesCurrentEnvironment(SearchPathMatcher *path);
extern Oid get_collation_oid(List *collname, bool missing_ok); extern Oid get_collation_oid(List *collname, bool missing_ok);
extern Oid get_conversion_oid(List *conname, bool missing_ok); extern Oid get_conversion_oid(List *conname, bool missing_ok);

View File

@ -111,7 +111,7 @@ typedef struct CachedPlanSource
List *query_list; /* list of Query nodes, or NIL if not valid */ List *query_list; /* list of Query nodes, or NIL if not valid */
List *relationOids; /* OIDs of relations the queries depend on */ List *relationOids; /* OIDs of relations the queries depend on */
List *invalItems; /* other dependencies, as PlanInvalItems */ List *invalItems; /* other dependencies, as PlanInvalItems */
struct OverrideSearchPath *search_path; /* search_path used for parsing struct SearchPathMatcher *search_path; /* search_path used for parsing
* and planning */ * and planning */
MemoryContext query_context; /* context holding the above, or NULL */ MemoryContext query_context; /* context holding the above, or NULL */
Oid rewriteRoleId; /* Role ID we did rewriting for */ Oid rewriteRoleId; /* Role ID we did rewriting for */

View File

@ -1686,7 +1686,6 @@ OuterJoinClauseInfo
OutputPluginCallbacks OutputPluginCallbacks
OutputPluginOptions OutputPluginOptions
OutputPluginOutputType OutputPluginOutputType
OverrideSearchPath
OverridingKind OverridingKind
PACE_HEADER PACE_HEADER
PACL PACL
@ -2463,6 +2462,7 @@ ScanState
ScanTypeControl ScanTypeControl
ScannerCallbackState ScannerCallbackState
SchemaQuery SchemaQuery
SearchPathMatcher
SecBuffer SecBuffer
SecBufferDesc SecBufferDesc
SecLabelItem SecLabelItem