Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 389AF635585 for ; Mon, 8 Mar 2010 22:18:53 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 58829-02 for ; Tue, 9 Mar 2010 02:18:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ananke.wxnz.net (ananke.wxnz.net [58.28.4.122]) by mail.postgresql.org (Postfix) with ESMTP id 9E38C634603 for ; Mon, 8 Mar 2010 22:18:42 -0400 (AST) Received: by ananke.wxnz.net (Postfix, from userid 89) id D8BB6171BB8; Tue, 9 Mar 2010 13:38:11 +1300 (NZDT) Received: from gonzo (ip-118-90-139-143.xdsl.xnet.co.nz [118.90.139.143]) by ananke.wxnz.net (Postfix) with ESMTP id 23668172EE4 for ; Tue, 9 Mar 2010 13:38:11 +1300 (NZDT) Received: from news by gonzo with local (Exim 4.69) (envelope-from ) id 1NnoyA-0002fG-MQ for pgsql-sql@postgresql.org; Sat, 06 Mar 2010 21:02:42 +1300 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: Does IMMUTABLE property propagate? Date: 6 Mar 2010 08:02:42 GMT Organization: Dis (not Dat) Organisation Lines: 45 Message-ID: References: <4B91C184.4090906@venaver.info> NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reversiblemaps.ath.cx 1267862562 10184 127.0.0.1 (6 Mar 2010 08:02:42 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-2 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 201003/50 X-Sequence-Number: 33757 On 2010-03-06, Petru Ghita wrote: > > Given f1(x) as IMMUTABLE and f2(x) as IMMUTABLE, and f3(f1,f2) as > IMMUTABLE, does the query planner cache the result of f3 and reuse it > or if you want to get a little more speed you better explicitly define > yourself f3 as IMMUTABLE? > > I had an aggregate query like: > > select id, > sum(p1*f1(a)/f2(b) as r1, > sum(p2*f1(a)/f2(b) as r2, > ... > sum(pn*f1(a)/f2(b) as rn > > ... > group by id; should be smart enough to know that. > Where f1(x) and f2(x) were defined as IMMUTABLE. > By the experiments I ran looks like after defining a new function > f3(a,b):= f1(a)/f2(b) and rewriting the query as: > > select id, > sum(p1*f3(a,b) as r1, > sum(p2*f3(a,b) as r2, > ... > sum(pn*f3(a,b) as rn > > ... > group by id; > > *Looks like* I got a little (5%) improvement in performance of the > query. Is there a way to find out if the function is re-evaluated each > time? add a " raise notce 'here'; " to it (if plpgsql) more likely 5% is the function call overhead.