Re: Does iscachable work?

From: Fran Fabrizio <ffabrizio(at)mmrd(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Does iscachable work?
Date: 2002-02-22 20:24:29
Message-ID: 3C76A8FD.5020200@mmrd.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:

> root <ffabrizio(at)mmrd(dot)com> writes:
>
>>I'm running PostgreSQL 7.1.3, and I have a query that uses one of my
>>functions:
>>
>
>>select findregion(entityid) from msg200;
>>
>
>>The findregion function is set to be 'with (iscachable)'. However, the
>>query takes upwards of 40 seconds to run, the first time and every time
>>thereafter, consistently. It doesn't seem like the caching is working.
>>
>
> I'm not sure what you think "iscachable" does ... but there certainly is
> not a cache that remembers the results of functions across statements.

Hrmmm. Ok. I have two observations to share in light of that...

The query above should still see improvement since findregion() will be
called with the same parameter multiple times within the same statement.
However, I just tested that and in practice, it runs at an average
of 23 seconds with caching, and 21 without. The nature of the data is
such that there's 20000 rows and only 115 possible parameters to the
function, so I would have expected to see a good deal of improvement
(somewhere around 99.5% of the function calls should have been eligible
to be pre-evaluated in this case).

The other observation is that the author of PostgreSQL Developer's
Handbook appears to indicate that it did cache across statements. The
text and examples on page 235 clearly show that this is his intended
usage.

-- QUOTE FROM BOOK --

Let's see how it works:
performance=# SELECT geomean(94,57);
geomean
-------
109.9317970380
(1 row)

Simply add WITH (iscachable) to the definition of the function, and the
results will be cached.

-- END QUOTE --

If it doesn't persist across statements, his example is quite useless.
=) That's quite misleading if it doesn't really work that way.

However, does my first observation seem odd to anyone else? And if not,
can someone give me an example of where using iscachable does help?

Thanks,
Fran

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kenneth Gangstoe 2002-02-22 20:40:31 game db
Previous Message Tom Lane 2002-02-22 20:20:39 Re: Regular Expression for 'and' instead of 'or'