Re: IMMUTABLE STABLE functions, daily updates - Mailing list pgsql-performance

From Craig Ringer
Subject Re: IMMUTABLE STABLE functions, daily updates
Date
Msg-id CAD2md3GG37L69TXLx5fu9kPDseDEGrGTdabCX0uzoXm4Cr+zkA@mail.gmail.com
Whole thread Raw
In response to Re: IMMUTABLE STABLE functions, daily updates  (Thom Brown <thom@linux.com>)
List pgsql-performance


On Nov 10, 2011 9:26 PM, "Thom Brown" <thom@linux.com> wrote:
>
> On 10 November 2011 13:05, Sorin Dudui <sd@wigeogis.com> wrote:
> > Hi,
> >
> >
> >
> > I have some functions that select data from tables which are daily or
> > monthly updated.  My functions are marked as STABLE. I am wondering if they
> > perform better if I mark they as IMMUTABLE?
>
> No.  IMMUTABLE is only appropriate when there is no access to table
> data from within the function

Sure it can be faster - the same way defining "fibonacci(int)" to always return 42 is faster, just incorrect.

You can sometimes kinda get away with it if you are willing to reindex, drop prepared statements, reload functions, etc when the result changes. I would not recommend it.

pgsql-performance by date:

Previous
From: Jay Levitt
Date:
Subject: Re: Subquery in a JOIN not getting restricted?
Next
From: Tom Lane
Date:
Subject: Re: Subquery in a JOIN not getting restricted?