Re: Does CREATE FUNCTION... WITH (ISCACHABLE) work?

From: "Joel Burton" <jburton(at)scw(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Does CREATE FUNCTION... WITH (ISCACHABLE) work?
Date: 2000-07-19 22:50:24
Message-ID: 3975F870.31979.AB8B7F7@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 19 Jul 2000, at 14:30, Tom Lane wrote:

> "Joel Burton" <jburton(at)scw(dot)org> writes:
> > I have a function that always returns the same answer given the same
> > input (no database lookups, etc.). The pg Users' Manual documents
> > the attribute 'iscachable' as allowing the database to parse the
> > results of the function and not keep looking it up.
>
> iscachable does not mean that the system will cache the results of the
> function across queries, it just means that the function needn't be
> re-evaluated multiple times for the same arguments within a single
> query. For example, given
>
> SELECT * from table1 where col = foo(42);
>
> If foo() is marked cachable then it's evaluated once during query
> planning; if not it's evaluated again for each row scanned in table1.

Sounds reasonable. But does it work as advertised?

CREATE FUNCTION foo(int) RETURNS int AS '
BEGIN
RAISE NOTICE ''hi'';
RETURN 1;
END;'
LANGUAGE 'plpgsql';

CREATE FUNCTION foocache(int) RETURNS int AS '
BEGIN
RAISE NOTICE ''hi'';
RETURN 1;
END;'
LANGUAGE 'plpgsql'
WITH (iscachable);

SELECT foo(1),foo(1),foo(1)
gives us 3 NOTICEs, as does
SELECT foocache(1), foocache(1), foocache(1)

So is it running the cached version a second time?

Thanks,

--
Joel Burton, Director of Information Systems -*- jburton(at)scw(dot)org
Support Center of Washington (www.scw.org)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Bitmead 2000-07-19 23:43:37 Re: [HACKERS] Re: PRIMARY KEY & INHERITANCE (fwd)
Previous Message Merrill Oveson 2000-07-19 22:22:23 unique constraint - bug?