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 55BEB9F9C18 for ; Wed, 17 May 2006 12:51:51 -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 40187-05 for ; Wed, 17 May 2006 12:51:42 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 034019FA226 for ; Wed, 17 May 2006 12:51:41 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id 7E28656427; Wed, 17 May 2006 10:51:40 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Wed, 17 May 2006 10:51:40 -0500 Date: Wed, 17 May 2006 10:51:40 -0500 From: "Jim C. Nasby" To: David Wheeler Cc: Christopher Kings-Lynne , Tom Lane , pgsql-performance Subject: Re: IMMUTABLE? Message-ID: <20060517155139.GS26212@pervasive.com> References: <2D4C0FA5-DB75-45EA-91D2-7B4F6DD55083@kineticode.com> <5211.1147749711@sss.pgh.pa.us> <3F0CF576-8C6F-433C-9942-BB36F4E1A194@kineticode.com> <5894.1147753901@sss.pgh.pa.us> <719F1E6C-4695-4FD2-A73B-0E3AE173B8F0@kineticode.com> <446A7C69.5030905@calorieking.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060517:david@kineticode.com::SLu1YGsn3HNNS6LP:00000000000000000 0000000000000000000000001CgK X-Hashcash: 1:20:060517:chris.kings-lynne@calorieking.com::2IFk6BgqQXVd3poS:0000 0000000000000000000000000I3/ X-Hashcash: 1:20:060517:tgl@sss.pgh.pa.us::Ck8Bal41/a3s2Avd:00000000000000000000 000000000000000000000000388g X-Hashcash: 1:20:060517:pgsql-performance@postgresql.org::4ttUBr6bJmWGrZtg:00000 0000000000000000000000000fCZ X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/362 X-Sequence-Number: 19149 On Tue, May 16, 2006 at 07:08:51PM -0700, David Wheeler wrote: > On May 16, 2006, at 18:29, Christopher Kings-Lynne wrote: > > >>Yes, but there are definitely programming cases where memoization/ > >>caching definitely helps. And it's easy to tell for a given > >>function whether or not it really helps by simply trying it with > >>CACHED and without. > >>Would this be a simple thing to implement? > > > >It's called a "table" :) > > http://www.justatheory.com/computers/databases/postgresql/ > higher_order_plpgsql.html > > Yes, I know. :-P But it'd be easier to have a CACHED keyword, of course. Rather than worrying about a generic form of memoization, what would be extremely valuable would be to improve detection of the same function being used multiple times in a query, ie: SELECT moo(x), moo(x)/2 FROM table; AFAIK PostgreSQL will currently execute moo(x) twice. Even if it knows how to optimize this brain-dead example, I think there are other examples it can't optimize right now. Having a much simpler memoization scheme that only works on a tuple-by-tuple basis would probably eliminate a lot of those (It wouldn't work for any executor node that has to read it's entire input before returning anything, though, such as sort). -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461