Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sO34W-00C57d-Sx for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Jun 2024 22:31:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sO34V-00DYOV-BK for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Jun 2024 22:30:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sO34V-00DYON-1s for pgsql-hackers@lists.postgresql.org; Sun, 30 Jun 2024 22:30:59 +0000 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sO34P-004N7O-37 for pgsql-hackers@postgresql.org; Sun, 30 Jun 2024 22:30:58 +0000 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-63bc513ade5so18948157b3.3 for ; Sun, 30 Jun 2024 15:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1719786650; x=1720391450; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=TKAulPBYcF4KBDM1VHnEhTGCRP4DU1ojo+SIOmMXD4M=; b=SPJfdteO1v9YpljRMr5DJmY0EXKBdGwDiDvZkSdVOi7IE9GDHUVerKeDIvqi78I1Vh 74RZOE4xeG2cfJbmHu8WpTYDEQgXIo4jdXOMauA9m0Uo5QDn3yWNPeZcPAIMBVzZHEBD 5HkNr7rxutRy6TZgv8Dgq8PI9c5o7DZxc/gdA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719786650; x=1720391450; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TKAulPBYcF4KBDM1VHnEhTGCRP4DU1ojo+SIOmMXD4M=; b=NSHmBYmkBfQRvsxONKVSlP548R36ZfqE6G/LLszn36fp0SXAfjfRohgyCHlfVtf51E w9/0UpXzTTUhDW2glQJi0fM0vuMwtzwJcyjDmYTAJIcdwbbDCM1iqWE1siW5Uu0WD9sE xDY8msQ6iGQ2F1dp3gVvRu70QYYTS95I3U5TCg/vKLGJpEIIW6YwaQmSUkeLXdIMUIML g2u2givP/L2WVtrVZveJkDD70eoFfALPnn8ZsyoO9rPmEXjCAgL7iGx9ZDyIklX/KBF7 5DISjHurVSgq0WpXjiDgiAGvhf2x7cXk6YosUgXTR4YDc+ELzkGbpJ6wtw3YYEsxCUoF Shfg== X-Forwarded-Encrypted: i=1; AJvYcCW0HY9fnZDCEdVWDmQmDpKbKOiEGr+oB8leI386R+Q2yk1rvsn4Ou4hVLZ8gmUUIz+Mwiz8hUwlWURXSzJdQSC7iXH/5/STZpekEsdf X-Gm-Message-State: AOJu0Yy4TWpBeAqqIGZ7QJtpuy+6gKh9hlRC6WeS9xyrR/QxA5UPilr2 9yQmTNWZ1VQN0/g+f6cBI5uMp8U7nhtUzfVIv7TzAMknRSULwcoRx2lz+DH5tQ== X-Google-Smtp-Source: AGHT+IH3JBkFAfqcdQrA3idjqAAogjG7QK0jwp+tZdwQXviqN35uLmGutLke4cu/MaPB9Nhrroi1kQ== X-Received: by 2002:a81:ae28:0:b0:64a:9fc7:3b15 with SMTP id 00721157ae682-64c72b54933mr45421937b3.26.1719786650594; Sun, 30 Jun 2024 15:30:50 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 00721157ae682-64a99e5c57fsm11490367b3.5.2024.06.30.15.30.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Jun 2024 15:30:50 -0700 (PDT) Date: Sun, 30 Jun 2024 15:30:47 -0700 From: Noah Misch To: Jeff Davis Cc: Nathan Bossart , Isaac Morland , pgsql-hackers@postgresql.org Subject: Re: Faster "SET search_path" Message-ID: <20240630223047.1f.nmisch@google.com> References: <20230802050720.GB866741@nathanxps13> <20230807223908.GB1284531@nathanxps13> <3b2d57ead15798adcbf6a53a15e35cdbadb2c147.camel@j-davis.com> <5bb4d9c21cc918e5d05021bf0d5e0e7d34a0377c.camel@j-davis.com> <695668acc40b937258985669f3d55b94cce82c3c.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <695668acc40b937258985669f3d55b94cce82c3c.camel@j-davis.com> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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.)