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 1tTNDh-0057lD-Kd for pgsql-general@arkaria.postgresql.org; Thu, 02 Jan 2025 15:34:45 +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 1tTNDg-00GTrV-U8 for pgsql-general@arkaria.postgresql.org; Thu, 02 Jan 2025 15:34:44 +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 1tTNDg-00GTrM-Iy for pgsql-general@lists.postgresql.org; Thu, 02 Jan 2025 15:34:44 +0000 Received: from gaoxing.magnetkern.de ([167.235.225.147]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tTNDd-002qSi-8E for pgsql-general@lists.postgresql.org; Thu, 02 Jan 2025 15:34:43 +0000 Received: from titanium.fritz.box (p200300c26f20ef00264bfefffe54b09c.dip0.t-ipconnect.de [IPv6:2003:c2:6f20:ef00:264b:feff:fe54:b09c]) by gaoxing.magnetkern.de (Postfix) with ESMTPSA id B15117332D; Thu, 02 Jan 2025 16:35:54 +0100 (CET) Date: Thu, 2 Jan 2025 16:34:40 +0100 From: Jan Behrens To: Pavel Stehule Cc: "David G. Johnston" , "pgsql-general@lists.postgresql.org" Subject: Re: search_path for PL/pgSQL functions partially cached? Message-Id: <20250102163440.17acbac07e2e32016cb5433c@magnetkern.de> In-Reply-To: References: <20241227205025.1d059f72c7c08d23c9648c26@magnetkern.de> <20241228004009.267f21b78394c934f27f9974@magnetkern.de> <20250101185504.3d50c571c3448512e94288e8@magnetkern.de> <20250102113727.1574b14fd677d164c32160bc@magnetkern.de> <20250102131547.f47d7eeb27c7a8256a8cd189@magnetkern.de> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; amd64-portbld-freebsd14.1) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2 Jan 2025 13:48:29 +0100 Pavel Stehule wrote: > čt 2. 1. 2025 v 13:15 odesílatel Jan Behrens > napsal: > > > On Thu, 2 Jan 2025 12:40:59 +0100 > > Pavel Stehule wrote: > > > > > How can you identify unwanted usage of non qualified identifiers from > > > wanted usage of non qualified identifiers? It is a common pattern for > > > sharding. Using not qualified identifiers of operators, functions is > > common > > > when you are using orafce extensions, etc. > > > > I don't fully understand the use-case. Could you elaborate? > > > > As I understand, even if identifiers are not fully-qualified, it is > > forbidden to use the search_path to refer to different database > > entities at run-time (as David pointed out). > > > > So I don't understand how a dynamic "search_path" could be used in any > > scenario within functions except when EXECUTE is involved. > > > > you don't need more databases > > schema one - customer x > schema two - customer y > > create table one.t1(..); create table one.t2(..); > create table two.t1(..); create table two.t2(..); > > set search_path to one; > -- work with data set of customer x > > set search_path to two; > -- work wit data set of customer y > > some times can be pretty ineffective to have database per customer - more > connect, disconnect in postgres is much more expensive than SET search_path > TO .. and maybe RESET plans; I guess that means there is a practical application where search_path MAY change at runtime IF done in different sessions or if the cache is reset using the DISCARD command: https://www.postgresql.org/docs/17/sql-discard.html I assume DISCARD PLANS would be the right command? This seems to be a very special case though. I think there should be a warning in the documentation of CREATE FUNCTION with regard to schemas anyway, though. Regards, Jan