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 1tRHUR-008THd-36 for pgsql-general@arkaria.postgresql.org; Fri, 27 Dec 2024 21:03:23 +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 1tRHUQ-00D8W6-Bh for pgsql-general@arkaria.postgresql.org; Fri, 27 Dec 2024 21:03:22 +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 1tRHUQ-00D8Vy-1E for pgsql-general@lists.postgresql.org; Fri, 27 Dec 2024 21:03:21 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tRHUN-001w9c-6z for pgsql-general@lists.postgresql.org; Fri, 27 Dec 2024 21:03:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4BRL3Hng2547822; Fri, 27 Dec 2024 16:03:17 -0500 From: Tom Lane To: "David G. Johnston" cc: Jan Behrens , "pgsql-general@lists.postgresql.org" Subject: Re: search_path for PL/pgSQL functions partially cached? In-reply-to: References: <20241227205025.1d059f72c7c08d23c9648c26@magnetkern.de> Comments: In-reply-to "David G. Johnston" message dated "Fri, 27 Dec 2024 13:26:28 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2547820.1735333397.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 27 Dec 2024 16:03:17 -0500 Message-ID: <2547821.1735333397@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > It is what it is - and if one is not careful one can end up writing > hard-to-understand and possibly buggy code due to the various execution > environments and caches involved. Yeah, I don't see this changing. The actual answer is that we have search_path-aware caching of expressions and query plans within a plpgsql function, which is why the call to foo() reacts to the current search path. But the types of plpgsql variables are only looked up on the first use (within a session). Perhaps we ought to work harder on that, but it seems like a lot of overhead to add for something that will benefit next to nobody. > I’ve never really understood why “%TYPE’ exists… Compatibility with Oracle, I imagine. I agree it's a bizarre feature. But you could get the same behavior without %TYPE, just by referencing some other type that has different declarations in different schemas. > Add qualification or attach a “set search_path” clause to “create > function”. Code stored in the server should not rely on the session > search_path. Yeah, adding "set search_path" is recommendable if you don't want to think hard about this stuff. regards, tom lane