Re: STABLE functions

From: Joachim Wieland <jwieland(at)kawo2(dot)rwth-aachen(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: STABLE functions
Date: 2003-04-25 14:50:08
Message-ID: 20030425145007.GA26172@mcknight.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Tom,

On Fri, Apr 25, 2003 at 10:01:44AM -0400, Tom Lane wrote:
> > I thought that this function is only executed once when declared as
> > STABLE,

> You are mistaken.

> If you'd declared it IMMUTABLE, then it would get constant-folded, but
> that may or may not be suitable for your purpose.

The function in question is not IMMUTABLE :-( It depends on database
lookups but won't change its results within one transaction.

Quotation from the docs:

| STABLE indicates that within a single table scan the function will
| consistently return the same result for the same argument values, but
| that ist result could change across SQL statements.

So why is a

SELECT ... FROM table WHERE col = f(...)

(with a STABLE function f) not a "single table scan" or why does
PostgreSQL re-calculate the value of f() here for every row?

Thanks a lot,
Joachim

--
*****PGP key available - send e-mail request*****
Due to circumstances beyond your control, you are master of your fate
and captain of your soul.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-04-25 15:13:06 Re: STABLE functions
Previous Message Bruce Momjian 2003-04-25 14:14:10 Re: close() vs. closesocket()