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 1seh9E-00AnYx-8L for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Aug 2024 20:32:40 +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 1seh9B-0012Ul-6v for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Aug 2024 20:32:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1seh9A-0012Ud-UY for pgsql-bugs@lists.postgresql.org; Thu, 15 Aug 2024 20:32:36 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1seh98-004ugq-DI for pgsql-bugs@lists.postgresql.org; Thu, 15 Aug 2024 20:32:35 +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 47FKWWIx613286; Thu, 15 Aug 2024 16:32:32 -0400 From: Tom Lane To: Dmytro Astapov cc: pgsql-bugs@lists.postgresql.org Subject: Re: Using current_user as an argument of pl/pgsql function affects collation of other arguments In-reply-to: References: Comments: In-reply-to Dmytro Astapov message dated "Wed, 14 Aug 2024 15:09:17 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <613284.1723753952.1@sss.pgh.pa.us> Date: Thu, 15 Aug 2024 16:32:32 -0400 Message-ID: <613285.1723753952@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dmytro Astapov writes: > As the subject implies, I am observing that > current_user/session_user/current_database/current_schema, when used as an > argument for pl/pgsql function, could affect execution plans of unrelated > queries inside that pl/pgsql function -- because they seemingly affect > collation for other arguments (I am not 100% sure about this last claim, > but the observed effects suggest that this might be the case). This is expected behavior. Those functions return type "name" not "text", and "name" is considered to have C collation. Then, in a call such as select_test('1',current_user); that is the only source of collation in the expression and so select_test is invoked with an input collation of "C", rather than whatever the database's default is. The most robust solution probably is to write explain select * from tbl where id = id_to_update COLLATE "default" regards, tom lane