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 1u2dCa-003Va8-SZ for pgsql-general@arkaria.postgresql.org; Wed, 09 Apr 2025 21:43:20 +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 1u2dCX-007WUy-OL for pgsql-general@arkaria.postgresql.org; Wed, 09 Apr 2025 21:43:18 +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 1u2dCX-007WUp-Dn for pgsql-general@lists.postgresql.org; Wed, 09 Apr 2025 21:43:17 +0000 Received: from fhigh-b1-smtp.messagingengine.com ([202.12.124.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u2dCV-004PUz-0s for pgsql-general@lists.postgresql.org; Wed, 09 Apr 2025 21:43:17 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 83BC8254014C; Wed, 9 Apr 2025 17:43:13 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Wed, 09 Apr 2025 17:43:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1744234993; x=1744321393; bh=7i+fuE1cJr9uI6gVgEf8zhJGm9Z6nOE3cN04R5RB/eY=; b= HBdCukqgKCaonQYmiBNyWzbjO8y/5/Z6UfMKvi9ykNE8tP7pfOlriKb6Odp4RsD8 QZYpYBVb5jw3DePj0H51gmqOiWtRVXWrPntdCrbla4gF0MuTyJXd7D409iCxjEp3 zK3bCT8KcegnvmManu5is14bhcLSKknF99d0IQMaJaPhtGY91JsrcEPmHF8JGBPm AwONF3FDIOEXU4m9xBcI5iMxy5+8Wp9R7FxnmCZvjFyI/QTUcuD05H0hr7bRU+t4 msZGldDLpL61iYuM6oQHb6Ovcu1B/J5mmYRLg9KE9rjKBKJrNOCpHUlzuYAuOs6u 1LLyJc8wFoX2++JR76mDAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1744234993; x= 1744321393; bh=7i+fuE1cJr9uI6gVgEf8zhJGm9Z6nOE3cN04R5RB/eY=; b=j KxxyUz+ItFfGbIklG9af2fXOQjPemk71EZBA4A9JDuJ6CkNC3M4za+Q0NXoEmCHg dJSBoN5ElZtwvYQlKggEcMUOEcQ7PlIEd5u6/3cQ/OeZcQWRXIUo38/In3lyllIH lN0SFu8dwYId3ayUiQZAbVTgxsWERaswvhg/4aa8BeVKYY3xzio/SfE2lpYGd8yp yOw+bez/sxNV27WQVNEd7QlWbINUkEQCAgb8unTd85AUGVL8JdRc3f+3YslYTDhx YPH6jMr/H+zH1g25+5wY5tZ3oUg/lHO1WQLpjXoUFKuou0FEue++YTnTl9YbWVeW u1mYrAojurayBXFQP0uFg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdejudduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddt vdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvh gvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepgfdufeekhfevfeel veeiueevhedvuddukeduvddvlefhueeuieejtdeuvdevvdeunecuffhomhgrihhnpehpoh hsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmpd hnsggprhgtphhtthhopeegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehnihgt ohestghrhihpthhonhgvtghtohhrrdgtohhmpdhrtghpthhtoheplhgruhhrvghniidrrg hlsggvsegthigsvghrthgvtgdrrghtpdhrtghpthhtohepshhplhgrrhhvseihrgdrrhhu pdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvg hsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Apr 2025 17:43:11 -0400 (EDT) Message-ID: Date: Wed, 9 Apr 2025 14:43:11 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Interesting case of IMMUTABLE significantly hurting performance To: Nico Williams , Laurenz Albe Cc: Olleg Samoylov , "pgsql-generallists.postgresql.org" References: <662101e2-5ca5-4bf5-9307-2519efde8690@ya.ru> <8687df7d49bc4b28b41c7cf4e9ad1e15d383b2fa.camel@cybertec.at> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/9/25 14:21, Nico Williams wrote: > On Wed, Apr 09, 2025 at 10:50:00PM +0200, Laurenz Albe wrote: >> The IMMUTABLE function cannot be inlined because to_char() is not IMMUTABLE. > > Q: Why would to_char() not be IMMUTABLE? > > A: Because it makes use of locales, and I guess the guc-timezone GUC, > which could change if the expression is ultimately used in a PlPgSQL > fragment, or if it's in a prepared statement. (I think.) > > That to_char is not immutable is not documented though. Though it's > clear when looking at the docs for the `jsonb_.*_tz()` functions. From here: https://www.postgresql.org/docs/current/catalog-pg-proc.html select proname, provolatile, prosrc from pg_proc where proname='to_char'; proname | provolatile | prosrc ---------+-------------+--------------------- to_char | s | timestamptz_to_char to_char | s | numeric_to_char to_char | s | int4_to_char to_char | s | int8_to_char to_char | s | float4_to_char to_char | s | float8_to_char to_char | s | interval_to_char to_char | s | timestamp_to_char Where 's' is: "It is s for “stable” functions, whose results (for fixed inputs) do not change within a scan." > > Nico -- Adrian Klaver adrian.klaver@aklaver.com