MCPcopy Create free account
hub / github.com/apache/cloudberry / OverrideSearchPathMatchesCurrent

Function OverrideSearchPathMatchesCurrent

src/backend/catalog/namespace.c:3579–3631  ·  view source on GitHub ↗

* OverrideSearchPathMatchesCurrent - does path match current setting? * * 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. * We make that case fast by keeping a generation counter that is advanced * whenever the active search path changes. */

Source from the content-addressed store, hash-verified

3577 * whenever the active search path changes.
3578 */
3579bool
3580OverrideSearchPathMatchesCurrent(OverrideSearchPath *path)
3581{
3582 ListCell *lc,
3583 *lcp;
3584
3585 recomputeNamespacePath();
3586
3587 /* Quick out if already known equal to active path. */
3588 if (path->generation == activePathGeneration)
3589 return true;
3590
3591 /* We scan down the activeSearchPath to see if it matches the input. */
3592 lc = list_head(activeSearchPath);
3593
3594 /* If path->addTemp, first item should be my temp namespace. */
3595 if (path->addTemp)
3596 {
3597 if (lc && lfirst_oid(lc) == myTempNamespace)
3598 lc = lnext(activeSearchPath, lc);
3599 else
3600 return false;
3601 }
3602 /* If path->addCatalog, next item should be pg_catalog. */
3603 if (path->addCatalog)
3604 {
3605 if (lc && lfirst_oid(lc) == PG_CATALOG_NAMESPACE)
3606 lc = lnext(activeSearchPath, lc);
3607 else
3608 return false;
3609 }
3610 /* We should now be looking at the activeCreationNamespace. */
3611 if (activeCreationNamespace != (lc ? lfirst_oid(lc) : InvalidOid))
3612 return false;
3613 /* The remainder of activeSearchPath should match path->schemas. */
3614 foreach(lcp, path->schemas)
3615 {
3616 if (lc && lfirst_oid(lc) == lfirst_oid(lcp))
3617 lc = lnext(activeSearchPath, lc);
3618 else
3619 return false;
3620 }
3621 if (lc)
3622 return false;
3623
3624 /*
3625 * Update path->generation so that future tests will return quickly, so
3626 * long as the active search path doesn't change.
3627 */
3628 path->generation = activePathGeneration;
3629
3630 return true;
3631}
3632
3633/*
3634 * PushOverrideSearchPath - temporarily override the search path

Callers 3

RevalidateCachedQueryFunction · 0.85
CachedPlanIsSimplyValidFunction · 0.85

Calls 4

recomputeNamespacePathFunction · 0.85
list_headFunction · 0.85
lnextFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected