Re: Faster "SET search_path" - Mailing list pgsql-hackers

From Noah Misch
Subject Re: Faster "SET search_path"
Date
Msg-id 20240630223047.1f.nmisch@google.com
Whole thread Raw
In response to Re: Faster "SET search_path"  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: Faster "SET search_path"
List pgsql-hackers
On Tue, Nov 14, 2023 at 08:13:25PM -0800, Jeff Davis wrote:
> On Thu, 2023-10-19 at 19:01 -0700, Jeff Davis wrote:
> > 0003: Cache for recomputeNamespacePath.
> 
> Committed

Commit f26c236 wrote:
>     Add cache for recomputeNamespacePath().
>     
>     When search_path is changed to something that was previously set, and
>     no invalidation happened in between, use the cached list of namespace
>     OIDs rather than recomputing them. This avoids syscache lookups and
>     ACL checks.

> --- a/src/backend/catalog/namespace.c
> +++ b/src/backend/catalog/namespace.c

> @@ -109,11 +110,13 @@
>   * activeSearchPath is always the actually active path; it points to
>   * to baseSearchPath which is the list derived from namespace_search_path.
>   *
> - * If baseSearchPathValid is false, then baseSearchPath (and other
> - * derived variables) need to be recomputed from namespace_search_path.
> - * We mark it invalid upon an assignment to namespace_search_path or receipt
> - * of a syscache invalidation event for pg_namespace.  The recomputation
> - * is done during the next lookup attempt.
> + * If baseSearchPathValid is false, then baseSearchPath (and other derived
> + * variables) need to be recomputed from namespace_search_path, or retrieved
> + * from the search path cache if there haven't been any syscache
> + * invalidations.  We mark it invalid upon an assignment to
> + * namespace_search_path or receipt of a syscache invalidation event for
> + * pg_namespace or pg_authid.  The recomputation is done during the next

You're caching the result of object_aclcheck(NamespaceRelationId, ...), so
pg_auth_members changes and pg_database changes also need to invalidate this
cache.  (pg_database affects the ACL_CREATE_TEMP case in
pg_namespace_aclmask_ext() and affects ROLE_PG_DATABASE_OWNER membership.)



pgsql-hackers by date:

Previous
From: Noah Misch
Date:
Subject: Re: MAINTAIN privilege -- what do we need to un-revert it?
Next
From: Jelte Fennema-Nio
Date:
Subject: Re: [EXTERNAL] Re: Add non-blocking version of PQcancel