pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Wheeler <david@kineticode.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: IMMUTABLE?
Date: Tue, 16 May 2006 00:31:41 -0400
Message-ID: <5894.1147753901@sss.pgh.pa.us> (raw)
In-Reply-To: <3F0CF576-8C6F-433C-9942-BB36F4E1A194@kineticode.com>
References: <2D4C0FA5-DB75-45EA-91D2-7B4F6DD55083@kineticode.com>
	<5211.1147749711@sss.pgh.pa.us>
	<3F0CF576-8C6F-433C-9942-BB36F4E1A194@kineticode.com>

David Wheeler <david@kineticode.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



view thread (11+ messages)  latest in thread

Message-ID: <5894.1147753901@sss.pgh.pa.us>
Permalink:  ../5894.1147753901@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5894.1147753901@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david@kineticode.com
  Subject: Re: IMMUTABLE?
  In-Reply-To: <5894.1147753901@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox