Re: Immutable function WAY slower than Stable function? - Mailing list pgsql-general

From Michal
Subject Re: Immutable function WAY slower than Stable function?
Date
Msg-id b3191dde-4775-dca6-81ea-d0760f3dd261@o2.pl
Whole thread Raw
In response to Re: Immutable function WAY slower than Stable function?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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.


pgsql-general by date:

Previous
From: Jack Cushman
Date:
Subject: Re: Duplicating data folder without tablespace, for read access
Next
From: Ken Tanzer
Date:
Subject: Will there ever be support for Row Level Security on Materialized Views?