Re: Faster "SET search_path"
Noah Misch <noah@leadboat.com>
From: Noah Misch <noah@leadboat.com>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Nathan Bossart <nathandbossart@gmail.com>, Isaac Morland <isaac.morland@gmail.com>, pgsql-hackers@postgresql.org
Date: 2024-06-30T22:30:47Z
Lists: 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.)
Commits
-
Fix missing invalidations for search_path cache.
- b3bd18294ee4 18.0 landed
- d3e076549b99 17.0 landed
-
Optimize SearchPathCache by saving the last entry.
- a86c61c9eefa 17.0 landed
-
Optimize check_search_path() by using SearchPathCache.
- ad57c2a7c586 17.0 landed
-
Be more paranoid about OOM in search_path cache.
- 8efa301532c8 17.0 landed
-
Add cache for recomputeNamespacePath().
- f26c2368dcae 17.0 landed
-
Transform proconfig for faster execution.
- 5765cfe18c59 17.0 landed