Skip site navigation (1) Skip section navigation (2)

Re: IMMUTABLE?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Wheeler <david(at)kineticode(dot)com>
Cc: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: IMMUTABLE?
Date: 2006-05-16 04:31:41
Message-ID: 5894.1147753901@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-performance
David Wheeler <david(at)kineticode(dot)com> writes:
> But seriously, the documentation says (as if I need to tell you, but  
> I was reading it again to make sure that I'm not insane):

>> IMMUTABLE indicates that the function always returns the same  
>> result when given the same argument values; that is, it does not do  
>> database lookups or otherwise use information not directly present  
>> in its argument list. If this option is given, any call of the  
>> function with all-constant arguments can be immediately replaced  
>> with the function value.

Sure.  As I read it, that's talking about a static transformation:
planner sees 2 + 2 (or if you prefer, int4pl(2,2)), planner runs the
function and replaces the expression with 4.  Nothing there about
memoization.

It's true that the system *could* memoize (or in our more usual
parlance, cache function values) given the assumptions embodied in
IMMUTABLE.  But we don't, and I don't see any statement in the docs
that promises that we do.  For 99% of the functions that the planner
deals with, memoization would be seriously counterproductive because
the function evaluation cost is comparable to if not less than the
lookup cost in a memo table.  (int4pl is a good case in point.)

			regards, tom lane

In response to

Responses

pgsql-performance by date

Next:From: Arjen van der MeijdenDate: 2006-05-16 09:33:32
Subject: Pgsql (and mysql) benchmark on T2000/Solaris and some profiling
Previous:From: David WheelerDate: 2006-05-16 04:22:03
Subject: Re: IMMUTABLE?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group