X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F379F9F9CEE for ; Tue, 16 May 2006 01:31:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 44195-09 for ; Tue, 16 May 2006 01:31:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 6A2259F944D for ; Tue, 16 May 2006 01:31:43 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k4G4VfgM005895; Tue, 16 May 2006 00:31:41 -0400 (EDT) To: David Wheeler cc: pgsql-performance Subject: Re: IMMUTABLE? 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> Comments: In-reply-to David Wheeler message dated "Mon, 15 May 2006 21:22:03 -0700" Date: Tue, 16 May 2006 00:31:41 -0400 Message-ID: <5894.1147753901@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/339 X-Sequence-Number: 19126 David Wheeler 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