pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedIMMUTABLE function's flag do not work: 7.3.4, plpgsql
7+ messages / 3 participants
[nested] [flat]
* IMMUTABLE function's flag do not work: 7.3.4, plpgsql
@ 2003-10-08 13:16 Andriy Tkachuk <ant@imt.com.ua>
0 siblings, 1 reply; 7+ messages in thread
From: Andriy Tkachuk @ 2003-10-08 13:16 UTC (permalink / raw)
To: pgsql-performance
Hi folks. I notice that immutable flag does nothing when i invoke
my plpgsql function within one session with same args.
tele=# SELECT version();
version
-------------------------------------------------------------
PostgreSQL 7.3.4 on i686-pc-linux-gnu, compiled by GCC 2.96
At first EXPLAIN ANALYZE shown strange runtime :)
[15:41]/0:ant@monstr:~>time psql -c 'EXPLAIN ANALYZE SELECT calc_total(1466476, 1062363600, 1064955599)' tele
QUERY PLAN
----------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.00..0.00 rows=1 loops=1)
Total runtime: 0.02 msec
^^^^^^^^^
(2 rows)
real 0m19.282s
^^^^^^^^^
At second. calc_total() is immutable function:
tele=# SELECT provolatile from pg_proc where proname = 'calc_total' and pronargs =3;
provolatile
-------------
i
but it seems that it's not cached in one session:
[15:38]/0:ant@monstr:~>psql tele
Welcome to psql 7.3.4, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
tele=# EXPLAIN ANALYZE SELECT calc_total(1466476, 1062363600, 1064955599);
QUERY PLAN
----------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.00..0.00 rows=1 loops=1)
Total runtime: 0.02 msec
(2 rows)
tele=# EXPLAIN ANALYZE SELECT calc_total(1466476, 1062363600, 1064955599);
QUERY PLAN
----------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.00..0.00 rows=1 loops=1)
Total runtime: 0.02 msec
(2 rows)
What i miss?
Thanks,
Andriy Tkachuk
http://www.imt.com.ua
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: IMMUTABLE function's flag do not work: 7.3.4, plpgsql
@ 2003-10-08 22:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andriy Tkachuk <ant@imt.com.ua>
0 siblings, 1 reply; 7+ messages in thread
From: Tom Lane @ 2003-10-08 22:22 UTC (permalink / raw)
To: Andriy Tkachuk <ant@imt.com.ua>; +Cc: pgsql-performance
Andriy Tkachuk <ant@imt.com.ua> writes:
> At second. calc_total() is immutable function:
> but it seems that it's not cached in one session:
It's not supposed to be.
The reason the "runtime" is small in your example is that the planner
executes the function call while preparing the plan, and this isn't
counted in EXPLAIN's runtime measurement. There's no claim anywhere
that the results of such an evaluation would be saved for other plans.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: IMMUTABLE function's flag do not work: 7.3.4, plpgsql
@ 2003-10-09 07:25 Andriy Tkachuk <ant@imt.com.ua>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 7+ messages in thread
From: Andriy Tkachuk @ 2003-10-09 07:25 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-performance
On Wed, 8 Oct 2003, Tom Lane wrote:
> Andriy Tkachuk <ant@imt.com.ua> writes:
> > At second. calc_total() is immutable function:
> > but it seems that it's not cached in one session:
>
> It's not supposed to be.
but it's written id doc:
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 parameter list. If this option is given, any call
of the function with all-constant arguments can be immediately
replaced with the function value.
I meant that the result of calc_total() is not "immediately replaced with the function value"
as it's written in doc, but it takes as long time as the first function call
in the session (with the same arguments).
Maybe i misunderstand something?
Thank you,
Andriy Tkachuk.
http://www.imt.com.ua
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: IMMUTABLE function's flag do not work: 7.3.4, plpgsql
@ 2003-10-09 16:41 Gaetano Mendola <mendola@bigfoot.com>
parent: Andriy Tkachuk <ant@imt.com.ua>
0 siblings, 1 reply; 7+ messages in thread
From: Gaetano Mendola @ 2003-10-09 16:41 UTC (permalink / raw)
To: pgsql-performance; +Cc: Andriy Tkachuk <ant@imt.com.ua>
Andriy Tkachuk wrote:
> On Wed, 8 Oct 2003, Tom Lane wrote:
>
>
>>Andriy Tkachuk <ant@imt.com.ua> writes:
>>
>>>At second. calc_total() is immutable function:
>>>but it seems that it's not cached in one session:
>>
>>It's not supposed to be.
>
>
> but it's written id doc:
>
> 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 parameter list. If this option is given, any call
> of the function with all-constant arguments can be immediately
> replaced with the function value.
The doc say "can be" not must and will be.
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: IMMUTABLE function's flag do not work: 7.3.4, plpgsql
@ 2003-10-10 07:15 Andriy Tkachuk <ant@imt.com.ua>
parent: Gaetano Mendola <mendola@bigfoot.com>
0 siblings, 1 reply; 7+ messages in thread
From: Andriy Tkachuk @ 2003-10-10 07:15 UTC (permalink / raw)
To: Gaetano Mendola <mendola@bigfoot.com>; +Cc: pgsql-performance
On Thu, 9 Oct 2003, Gaetano Mendola wrote:
> Andriy Tkachuk wrote:
> > On Wed, 8 Oct 2003, Tom Lane wrote:
> >
> >
> >>Andriy Tkachuk <ant@imt.com.ua> writes:
> >>
> >>>At second. calc_total() is immutable function:
> >>>but it seems that it's not cached in one session:
> >>
> >>It's not supposed to be.
> >
> >
> > but it's written id doc:
> >
> > 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 parameter list. If this option is given, any call
> > of the function with all-constant arguments can be immediately
> > replaced with the function value.
>
> The doc say "can be" not must and will be.
ok, but on what it depends on?
thanks,
andriy
http://www.imt.com.ua
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: IMMUTABLE function's flag do not work: 7.3.4, plpgsql
@ 2003-10-12 21:28 Gaetano Mendola <mendola@bigfoot.com>
parent: Andriy Tkachuk <ant@imt.com.ua>
0 siblings, 1 reply; 7+ messages in thread
From: Gaetano Mendola @ 2003-10-12 21:28 UTC (permalink / raw)
To: pgsql-performance; +Cc: Andriy Tkachuk <ant@imt.com.ua>
Andriy Tkachuk wrote:
> On Thu, 9 Oct 2003, Gaetano Mendola wrote:
>>Andriy Tkachuk wrote:
>>>On Wed, 8 Oct 2003, Tom Lane wrote:
>>>>Andriy Tkachuk <ant@imt.com.ua> writes:
>>>>>At second. calc_total() is immutable function:
>>>>>but it seems that it's not cached in one session:
>>>>
>>>>It's not supposed to be.
>>>
>>>
>>>but it's written id doc:
>>>
>>> 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 parameter list. If this option is given, any call
>>> of the function with all-constant arguments can be immediately
>>> replaced with the function value.
>>
>>The doc say "can be" not must and will be.
>
>
> ok, but on what it depends on?
For example in:
select * from T where f_immutable ( 4 ) = T.id;
in this case f_immutable will be evaluated once.
select * from T where f_immutable ( T.id ) = X;
here f_immutable will be avaluated for each different T.id.
Regards
Gaetano Mendola
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: IMMUTABLE function's flag do not work: 7.3.4, plpgsql
@ 2003-10-13 07:32 Andriy Tkachuk <ant@imt.com.ua>
parent: Gaetano Mendola <mendola@bigfoot.com>
0 siblings, 0 replies; 7+ messages in thread
From: Andriy Tkachuk @ 2003-10-13 07:32 UTC (permalink / raw)
To: Gaetano Mendola <mendola@bigfoot.com>; +Cc: pgsql-performance
Oh, Gaetano, didn't you see in my first letter of this topic
that args are the same in session (they are constant)?
The first paragraf of my first letter of this topic was:
< Hi folks. I notice that immutable flag does nothing when i invoke
< my plpgsql function within one session with same args.
^^^^^^^^^^^^^^
... ok, mabe i should say "constant args" as in doc.
Anyway, thank you for attention and willing to help.
regards, andriy tkachuk (http://imt.com.ua)
On Sun, 12 Oct 2003, Gaetano Mendola wrote:
> Andriy Tkachuk wrote:
>
> > On Thu, 9 Oct 2003, Gaetano Mendola wrote:
> >>Andriy Tkachuk wrote:
> >>>On Wed, 8 Oct 2003, Tom Lane wrote:
> >>>>Andriy Tkachuk <ant@imt.com.ua> writes:
> >>>>>At second. calc_total() is immutable function:
> >>>>>but it seems that it's not cached in one session:
> >>>>
> >>>>It's not supposed to be.
> >>>
> >>>
> >>>but it's written id doc:
> >>>
> >>> 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 parameter list. If this option is given, any call
> >>> of the function with all-constant arguments can be immediately
> >>> replaced with the function value.
> >>
> >>The doc say "can be" not must and will be.
> >
> >
> > ok, but on what it depends on?
>
> For example in:
>
> select * from T where f_immutable ( 4 ) = T.id;
>
>
> in this case f_immutable will be evaluated once.
>
>
>
> select * from T where f_immutable ( T.id ) = X;
>
> here f_immutable will be avaluated for each different T.id.
>
> Regards
> Gaetano Mendola
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2003-10-13 07:32 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-08 13:16 IMMUTABLE function's flag do not work: 7.3.4, plpgsql Andriy Tkachuk <ant@imt.com.ua>
2003-10-08 22:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-10-09 07:25 ` Andriy Tkachuk <ant@imt.com.ua>
2003-10-09 16:41 ` Gaetano Mendola <mendola@bigfoot.com>
2003-10-10 07:15 ` Andriy Tkachuk <ant@imt.com.ua>
2003-10-12 21:28 ` Gaetano Mendola <mendola@bigfoot.com>
2003-10-13 07:32 ` Andriy Tkachuk <ant@imt.com.ua>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox