Re: Function Volatility

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar>
Cc: "'SQL Postgresql List'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Function Volatility
Date: 2007-09-10 02:15:24
Message-ID: 15490.1189390524@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar> writes:
> I am not sure if I am understanding volatility.

You're not.

> What bother me are the 3 "been here" messages. As the function is immutable
> and the parameter remains unchanged needs the planner actually execute the
> function 3 times?

The IMMUTABLE marker is a promise from you to the system that it is safe
to optimize away multiple calls to the function. It is not a promise
from the system to you that the system will expend unlimited amounts of
energy to detect duplicate calls. The majority of the immutable
functions in Postgres are things like int4pl(), where it would obviously
be silly to expend any cycles at all on looking for duplicate calls such
as you show here.

In practice what will happen is that each textual call will be folded to
a constant separately. The advantage comes from not having to repeat
the call for each row processed by a query, not from saving work within
a row.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-09-10 02:51:42 Re: postgresql HEAD build failure
Previous Message Alvaro Herrera 2007-09-10 01:43:18 Re: postgresql HEAD build failure