Re: Unclear documentation (IMMUTABLE functions)

From: Daniel Schreiber <daniel(dot)schreiber(at)s1999(dot)tu-chemnitz(dot)de>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Unclear documentation (IMMUTABLE functions)
Date: 2003-09-05 15:57:57
Message-ID: 200309051757.57259.daniel.schreiber@s1999.tu-chemnitz.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Am Freitag, 5. September 2003 17:05 schrieb Tom Lane:
> Daniel Schreiber <daniel(dot)schreiber(at)s1999(dot)tu-chemnitz(dot)de> writes:
> > A question on IMMUTABLE functions: do they only have to return the same
> > value during a session/connection or during the databse server's
> > lifetime?
>
> Lifetime, I'd say, since among other things IMMUTABLE is considered to
> mean that it's okay to build an index on the function's results.
>
> Of course, you can cheat: the system makes no attempt to verify whether
> a function that you say is IMMUTABLE really is. There are cases where
> it's useful to lie about the mutability property of a function. What
> you are basically controlling here is whether the planner will deem it
> safe to pre-evaluate a call of the function. Unless you actually do
> build a functional index using a function, I doubt it could matter
> whether the results change from one session to the next.

Okay, thanks, I think I got it now.

> > I wrote a function that uses the CURRENT_USER session variable, and for
> > my current usage it is very important, that it returns a different value
> > for each database connection.
>
> CURRENT_USER is marked STABLE, not IMMUTABLE. Not sure what your point
> is here.

Okay, thanks for the help. I will rewrite the function as STABLE. Btw: is
there documentation which parts in the environment are STABLE/IMMUTABLE?

Thanks,
Daniel Schreiber
--
Daniel Schreiber | ICQ: 220903493
GPG encrypted Mail welcome! Key ID: 25A6B489
Chemnitzer Linux-Tag:
http://www.tu-chemnitz.de/linux/tag/

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2003-09-05 16:47:13 Re: Unclear documentation (IMMUTABLE functions)
Previous Message Daniel Schreiber 2003-09-05 15:57:43 Re: Unclear documentation (IMMUTABLE functions)