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 1u2kXG-005Okt-AX for pgsql-general@arkaria.postgresql.org; Thu, 10 Apr 2025 05:33:10 +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 1u2kXC-008yh2-Si for pgsql-general@arkaria.postgresql.org; Thu, 10 Apr 2025 05:33:07 +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 1u2kXC-008ygp-DP for pgsql-general@lists.postgresql.org; Thu, 10 Apr 2025 05:33:06 +0000 Received: from forward502d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:d502]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u2kXA-004T0o-0e for pgsql-general@lists.postgresql.org; Thu, 10 Apr 2025 05:33:06 +0000 Received: from mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net [IPv6:2a02:6b8:c43:c94:0:640:bcb2:0]) by forward502d.mail.yandex.net (Yandex) with ESMTPS id 6C5E9616EE; Thu, 10 Apr 2025 08:33:02 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id 1XX14v7LmmI0-tkbCRutC; Thu, 10 Apr 2025 08:33:02 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ya.ru; s=mail; t=1744263182; bh=1eqG4x2N3jF15hNc/9oSbpwF6JWyUfx2qKp8y90qmb0=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=k0QrMuru2Ud7B9DtXWRL+gCv9mfqEJR8vcWchoHoVYD0Ace4vo4HRnkLj7gxrUgLJ ydl6dn+vNg1eY/KFB4Nj4gnlTDsbacSKuJBuiOF/gi3myQE5eGsvzlsb5I/kX4dLjV mPmM4Cdl8h7+dnglkhiJFtob5YlD2U0JSgMWdU/w= Authentication-Results: mail-nwsmtp-smtp-production-main-52.klg.yp-c.yandex.net; dkim=pass header.i=@ya.ru Message-ID: <379a1e13-c775-4fb5-a444-b41308996cc4@ya.ru> Date: Thu, 10 Apr 2025 08:33:02 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Interesting case of IMMUTABLE significantly hurting performance To: Tom Lane Cc: "pgsql-generallists.postgresql.org" References: <662101e2-5ca5-4bf5-9307-2519efde8690@ya.ru> <8687df7d49bc4b28b41c7cf4e9ad1e15d383b2fa.camel@cybertec.at> <373227.1744236488@sss.pgh.pa.us> Content-Language: en-US From: Olleg Samoylov In-Reply-To: <373227.1744236488@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10.04.2025 01:08, Tom Lane wrote: > Yeah. The assumption is that you had a reason for marking the > function IMMUTABLE and you want the planner to treat it that way > even if it isn't really. (There are valid use-cases for that, for > instance if you want calls to the function to be constant-folded.) > regards, tom lane Well, to_char(bigint, text) indeed not immutable, because in some pattern it uses get information from locale. For instance,'SLDG' patterns. But in case of CREATE OR REPLACE FUNCTION formatted_num_immutable(p_summa bigint) RETURNS text LANGUAGE sql IMMUTABLE STRICT RETURN ltrim(to_char(p_summa, '999 999 999 999 999 999 999 999')); to_char do not use locale information in this pattern. So it is correct conclude that to_char is immutable with this pattern and formatted_num_immutable too. I did not lie to the planner. So this is looked "strange", immutable function marked as immutable function can not be inlined, but exactly the same function marked as volatile do. -- Olleg