[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pgsql-performance
Subject:    Re: [PERFORM] IMMUTABLE STABLE functions, daily updates
From:       Craig Ringer <ringerc () ringerc ! id ! au>
Date:       2011-11-10 14:28:10
Message-ID: CAD2md3GG37L69TXLx5fu9kPDseDEGrGTdabCX0uzoXm4Cr+zkA () mail ! gmail ! com
[Download RAW message or body]

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.

[Attachment #3 (text/html)]

<p><br>
On Nov 10, 2011 9:26 PM, &quot;Thom Brown&quot; &lt;<a \
href="mailto:thom@linux.com">thom@linux.com</a>&gt; wrote:<br> &gt;<br>
&gt; On 10 November 2011 13:05, Sorin Dudui &lt;<a \
href="mailto:sd@wigeogis.com">sd@wigeogis.com</a>&gt; wrote:<br> &gt; &gt; Hi,<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; I have some functions that select data from tables which are daily or<br>
&gt; &gt; monthly updated.   My functions are marked as STABLE. I am wondering if \
they<br> &gt; &gt; perform better if I mark they as IMMUTABLE?<br>
&gt;<br>
&gt; No.   IMMUTABLE is only appropriate when there is no access to table<br>
&gt; data from within the function</p>
<p>Sure it can be faster - the same way defining &quot;fibonacci(int)&quot; to always \
return 42 is faster, just incorrect.</p> <p>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.</p>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic