Re: how to avoid repeating expensive computation in select

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bob Price <rjp_email(at)yahoo(dot)com>
Cc: Bill Moran <wmoran(at)potentialtech(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: how to avoid repeating expensive computation in select
Date: 2011-02-03 22:33:30
Message-ID: 3854.1296772410@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bob Price <rjp_email(at)yahoo(dot)com> writes:
> If I set the COST of expensivefunc high, and label it IMMUTABLE, will the query executor note that the two invocations to expensivefunc have the same inputs so it can only call it once and re-use the result the second time?

No. There is a myth prevalent among certain wishful thinkers that
IMMUTABLE does something like that, but it doesn't. IMMUTABLE only
licenses the planner to fold a call *with constant arguments* into a
constant result, by executing the function once before the query
actually starts. Textually distinct calls of a function are not folded
together in any case.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-02-03 22:43:56 Re: how to avoid repeating expensive computation in select
Previous Message Nicklas Avén 2011-02-03 21:46:25 Re: how to avoid repeating expensive computation in select