Skip to content

Commit 96d66bc

Browse files
committed
Improve performance of OverrideSearchPathMatchesCurrent().
This function was initially coded on the assumption that it would not be performance-critical, but that turns out to be wrong in workloads that are heavily dependent on the speed of plpgsql functions. Speed it up by hard-coding the comparison rules, thereby avoiding palloc/pfree traffic from creating and immediately freeing an OverrideSearchPath object. Per report from Scott Marlowe.
1 parent e384ed6 commit 96d66bc

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

src/backend/catalog/namespace.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,20 +3145,44 @@ CopyOverrideSearchPath(OverrideSearchPath *path)
31453145
bool
31463146
OverrideSearchPathMatchesCurrent(OverrideSearchPath *path)
31473147
{
3148-
/* Easiest way to do this is GetOverrideSearchPath() and compare */
3149-
bool result;
3150-
OverrideSearchPath *cur;
3148+
ListCell *lc,
3149+
*lcp;
31513150

3152-
cur = GetOverrideSearchPath(CurrentMemoryContext);
3153-
if (path->addCatalog == cur->addCatalog &&
3154-
path->addTemp == cur->addTemp &&
3155-
equal(path->schemas, cur->schemas))
3156-
result = true;
3157-
else
3158-
result = false;
3159-
list_free(cur->schemas);
3160-
pfree(cur);
3161-
return result;
3151+
recomputeNamespacePath();
3152+
3153+
/* We scan down the activeSearchPath to see if it matches the input. */
3154+
lc = list_head(activeSearchPath);
3155+
3156+
/* If path->addTemp, first item should be my temp namespace. */
3157+
if (path->addTemp)
3158+
{
3159+
if (lc && lfirst_oid(lc) == myTempNamespace)
3160+
lc = lnext(lc);
3161+
else
3162+
return false;
3163+
}
3164+
/* If path->addCatalog, next item should be pg_catalog. */
3165+
if (path->addCatalog)
3166+
{
3167+
if (lc && lfirst_oid(lc) == PG_CATALOG_NAMESPACE)
3168+
lc = lnext(lc);
3169+
else
3170+
return false;
3171+
}
3172+
/* We should now be looking at the activeCreationNamespace. */
3173+
if (activeCreationNamespace != (lc ? lfirst_oid(lc) : InvalidOid))
3174+
return false;
3175+
/* The remainder of activeSearchPath should match path->schemas. */
3176+
foreach(lcp, path->schemas)
3177+
{
3178+
if (lc && lfirst_oid(lc) == lfirst_oid(lcp))
3179+
lc = lnext(lc);
3180+
else
3181+
return false;
3182+
}
3183+
if (lc)
3184+
return false;
3185+
return true;
31623186
}
31633187

31643188
/*

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