Re: Does IMMUTABLE property propagate? - Mailing list pgsql-sql

From Greg Stark
Subject Re: Does IMMUTABLE property propagate?
Date
Msg-id 407d949e1003060645i408e0648te67dfd722172f76a@mail.gmail.com
Whole thread Raw
In response to Does IMMUTABLE property propagate?  (Petru Ghita <petrutz@venaver.info>)
Responses Re: Does IMMUTABLE property propagate?
List pgsql-sql
<p>The immutable property had nothing to do with caching results. Postgres never caches the results of functions. The
immutableproperty is used top determine if it's safe to use indexes or other plans that avoid evaluating an expression
repeatedly.<p><blockquotetype="cite">On 6 Mar 2010 02:45, "Petru Ghita" <<a
href="mailto:petrutz@venaver.info">petrutz@venaver.info</a>>wrote:<br /><br />-----BEGIN PGP SIGNED MESSAGE-----<br
/>Hash: SHA1<br /><br /> Given f1(x) as IMMUTABLE and f2(x) as IMMUTABLE, and f3(f1,f2) as<br /> IMMUTABLE, does the
queryplanner cache the result of f3 and reuse it<br /> or if you want to get a little more speed you better explicitly
define<br/> yourself f3 as IMMUTABLE?<br /><br /> I had an aggregate query like:<br /><br /> select id,<br />      
sum(p1*f1(a)/f2(b)as r1,<br />       sum(p2*f1(a)/f2(b) as r2,<br />       ...<br />       sum(pn*f1(a)/f2(b) as rn<br
/><br/> ...<br /> group by id;<br /><br /> Where f1(x) and f2(x) were defined as IMMUTABLE.<br /><br /> By the
experimentsI ran looks like after defining a new function<br /> f3(a,b):= f1(a)/f2(b) and rewriting the query as:<br
/><br/> select id,<br />       sum(p1*f3(a,b) as r1,<br />       sum(p2*f3(a,b) as r2,<br />       ...<br />      
sum(pn*f3(a,b)as rn<br /><br /> ...<br /> group by id;<br /><br /> *Looks like* I got a little (5%) improvement in
performanceof the<br /> query. Is there a way to find out if the function is re-evaluated each<br /> time?<br /> Is
thisthe recommended way to proceed?<br /><br /> Thank you!<br /><br /> Petru Ghita<br /> -----BEGIN PGP
SIGNATURE-----<br/> Version: GnuPG v1.4.9 (MingW32)<br /> Comment: Using GnuPG with Mozilla - <a
href="http://enigmail.mozdev.org/"target="_blank">http://enigmail.mozdev.org/</a><br /><br />
iEYEARECAAYFAkuRwYQACgkQt6IL6XzynQTHEgCffi2QMWkkvTIsuglsanvcUyRB<br/> I+wAoKr22B7FJJVDCssGKGwB8zr4NjQG<br /> =V/BS<br
/>-----END PGP SIGNATURE-----<br /><font color="#888888"><br /><br /> --<br /> Sent via pgsql-sql mailing list (<a
href="mailto:pgsql-sql@postgresql.org">pgsql-sql@postgresql.org</a>)<br/> To make changes to your subscription:<br /><a
href="http://www.postgresql.org/mailpref/pgsql-sql"target="_blank">http://www.postgresql.org/mailpref/pgsql-sql</a><br
/></font></blockquote>

pgsql-sql by date:

Previous
From: Louis-David Mitterrand
Date:
Subject: Re: an aggregate to return max() - 1 value?
Next
From: "Little, Douglas"
Date:
Subject: Assigning NEW. anomoly