pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Strange behaviour ( function cachable )
3+ messages / 2 participants
[nested] [flat]

* Strange behaviour ( function cachable )
@ 2002-12-18 19:07  Gaetano Mendola <mendola@bigfoot.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Gaetano Mendola @ 2002-12-18 19:07 UTC (permalink / raw)
  To: pgsql-admin

I wrote some days ago about the behaviour that I notice
if I call a function cachable inside another not cachable,
I was wrong ?
I expected that if a function is cachable and is used
inside a select like:

SELECT * FROM foo WHERE id  = my_func( a_param )

then the function my_func is called one for each different value
of    a_param. But seems that this behaviour happen only in
stand alone query not if that query is executed inside another function.


Ciao
Gaetano






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Strange behaviour ( function cachable )
@ 2002-12-18 19:16  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Gaetano Mendola <mendola@bigfoot.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2002-12-18 19:16 UTC (permalink / raw)
  To: Gaetano Mendola <mendola@bigfoot.com>; +Cc: pgsql-admin

"Gaetano Mendola" <mendola@bigfoot.com> writes:
> I expected that if a function is cachable and is used
> inside a select like:
> SELECT * FROM foo WHERE id  = my_func( a_param )
> then the function my_func is called one for each different value
> of    a_param.

That is not what "cachable" means to Postgres.  There is no function
result cache such as you seem to envision.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Strange behaviour ( function cachable )
@ 2002-12-19 08:59  Gaetano Mendola <mendola@bigfoot.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Gaetano Mendola @ 2002-12-19 08:59 UTC (permalink / raw)
  To: pgsql-admin


"Tom Lane" <tgl@sss.pgh.pa.us> wrote in message
news:11105.1040238975@sss.pgh.pa.us...
> "Gaetano Mendola" <mendola@bigfoot.com> writes:
> > I expected that if a function is cachable and is used
> > inside a select like:
> > SELECT * FROM foo WHERE id  = my_func( a_param )
> > then the function my_func is called one for each different value
> > of    a_param.
>
> That is not what "cachable" means to Postgres.  There is no function
> result cache such as you seem to envision.
>
> regards, tom lane


Just to understand, do you mean that the following behaviour is
correct?

# create table test( a int, b int );
CREATE

# insert into test values (1,2);
INSERT 79298997 1
# insert into test values (1,2);
INSERT 79298998 1
# insert into test values (1,2);
INSERT 79298999 1


#select * from test where a = sp_cache( 3 );
NOTICE: CALLED
 a | b
---+---
(0 rows)

#select sp_test ( 4);
NOTICE:  CALLED
NOTICE:  CALLED
NOTICE:  CALLED
 sp_test
---------

(1 row)


where sp_cache is a function declared ( iscachable )
and do a notice each time that is called
and sp_test is a function that perform:
"select * from test where a = sp_cache( 3 )"

How you can see in the first case I see only a NOTICE
in the second case I see 3 NOTICE, why ? Am I wrong ?


Ciao
Gaetano








^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-12-19 08:59 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-12-18 19:07 Strange behaviour ( function cachable ) Gaetano Mendola <mendola@bigfoot.com>
2002-12-18 19:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-12-19 08:59   ` Gaetano Mendola <mendola@bigfoot.com>

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