Re: IMMUTABLE STABLE functions, daily updates

From: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
To: Thom Brown <thom(at)linux(dot)com>
Cc: Sorin Dudui <sd(at)wigeogis(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: IMMUTABLE STABLE functions, daily updates
Date: 2011-11-10 14:28:10
Message-ID: CAD2md3GG37L69TXLx5fu9kPDseDEGrGTdabCX0uzoXm4Cr+zkA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Nov 10, 2011 9:26 PM, "Thom Brown" <thom(at)linux(dot)com> wrote:
>
> On 10 November 2011 13:05, Sorin Dudui <sd(at)wigeogis(dot)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.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2011-11-10 15:22:48 Re: Subquery in a JOIN not getting restricted?
Previous Message Jay Levitt 2011-11-10 13:52:23 Re: Subquery in a JOIN not getting restricted?