|
Home > Archive > PostgreSQL Hacks > October 2005 > IMMUTABLE bug ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I cant get the IMMUTABLE modifier meaning.
The 'testme' IMMUTABLE function is invoked 3 times
in the following query:
# select testme(1), testme(1), testme(1);
NOTICE: called
NOTICE: called
NOTICE: called
testme | testme | testme
--------+--------+--------
ret | ret | ret
(1 row)
Why is so ? shouldn't the IMMUTABLE keywork make
it a single call ?
From the 8.0 manual :
IMMUTABLE indicates that the function always returns the same result
when given the same argument values; that is, it does not do database
lookups or otherwise use information not directly present in its
argument list. If this option is given, any call of the function
with all-constant arguments can be immediately replaced with the
function value.
The function definition:
CREATE OR REPLACE FUNCTION testme(integer) RETURNS text AS
' BEGIN
RAISE NOTICE ''called'';
return ''ret''::text;
END ' LANGUAGE 'plpgsql' IMMUTABLE STRICT;
PostgreSQL version 8.0.0
--strk;
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?
http://archives.postgresql.org
| |
| Tom Lane 2005-10-27, 8:14 am |
| strk <strk@keybit.net> writes:
> Why is so ? shouldn't the IMMUTABLE keywork make
> it a single call ?
No. There is no function value cache. What does happen here is that
the planner folds those calls to constants at plan time, instead of at
run time. Try
select testme(1) from some-table-with-multiple-rows
and note there's only one call not N.
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
|
|
|
|
|