public inbox for [email protected]  
help / color / mirror / Atom feed
From: Olleg Samoylov <[email protected]>
To: Tom Lane <[email protected]>
Cc: pgsql-generallists.postgresql.org <[email protected]>
Subject: Re: Interesting case of IMMUTABLE significantly hurting performance
Date: Thu, 10 Apr 2025 08:33:02 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<CAKFQuwY51Us6LeBxtdL7MbHpJkxYpWtMOHJAhUoXXN2p5f1JfQ@mail.gmail.com>
	<[email protected]>



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







view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Interesting case of IMMUTABLE significantly hurting performance
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox