Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpivM-0003cd-H4 for pgsql-general@arkaria.postgresql.org; Tue, 14 Aug 2018 23:40:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fpivK-00089d-RD for pgsql-general@arkaria.postgresql.org; Tue, 14 Aug 2018 23:40:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpivK-000896-Fo for pgsql-general@lists.postgresql.org; Tue, 14 Aug 2018 23:40:26 +0000 Received: from mx-out.tlen.pl ([193.222.135.145]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpivH-0007Fz-4C for pgsql-general@postgresql.org; Tue, 14 Aug 2018 23:40:25 +0000 Received: (wp-smtpd smtp.tlen.pl 29641 invoked from network); 15 Aug 2018 01:40:18 +0200 Received: from user-94-254-148-14.play-internet.pl (HELO [192.168.1.3]) (michal-ok@o2.pl@[94.254.148.14]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 15 Aug 2018 01:40:18 +0200 Subject: Re: Immutable function WAY slower than Stable function? To: Tom Lane , Ken Tanzer Cc: Adrian Klaver , PG-General Mailing List References: <03120a03-75d0-ad6c-691c-35ca7e7fccfa@aklaver.com> <27336.1533609731@sss.pgh.pa.us> <24954.1533658221@sss.pgh.pa.us> From: Michal Message-ID: Date: Wed, 15 Aug 2018 01:40:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4 MIME-Version: 1.0 In-Reply-To: <24954.1533658221@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-WP-MailID: d15bd2bed72d682ab47888770ea3c2b3 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 000000A [UTPE] List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018.08.07 18:10, Tom Lane wrote: > I've had a to-do item to rewrite and improve the SQL function cache > mechanism for a long time, but I hadn't thought it was high priority. > Maybe it should be. > > In the meantime, I think you could dodge the issue by converting either > level of function into plpgsql. Or just be careful about inline-ability > of convenience wrappers. I now remember I stumbled across this same problem last year when I needed an immutable unaccent() function for the purpose of creating a functional index. I simply wrapped unaccent(), which is stable, in an immutable custom function (and accepting the need to recreate the index in case when unaccent rules change). I can't remember the specifics but I was also surprised to learn that query execution plans were not optimized at all when the function was immutable and in some cases they were even slower than when the function was stable, quite contrary to all logic and to what the docs say. So I think it would be great if this issue were resolved in Postgres.