func() & select func() - Mailing list pgsql-hackers

From Hiroshi Inoue
Subject func() & select func()
Date
Msg-id 000901c01322$e6bf81e0$2801007e@tpf.co.jp
Whole thread Raw
Responses Re: func() & select func()
List pgsql-hackers
Hi all,

I have seen discussions about iscachable attribute of
functions. Now I'm confused to see a solution in 6.5
(by Shigeru Matsumoto).
=# explain select * from pg_class where oid=1259;

Index Scan using pg_class_oid_index on pg_class  (cost=0.00..2.01rows=1 width=92) 

1) Using non-cachable function f() =# create function f(oid) returns oid as   '    select $1;   ' language 'sql'; =#
explainselect * from pg_class where oid=f(1259);
 
 Seq Scan on pg_class  (cost=0.00..3.17 rows=1 width=92) 

Seems reasonable.

2) Using select f() =# explain select * from pg_class where oid=(select f(1259)); 
 Index Scan using pg_class_oid_index on pg_class  (cost=0.00..2.01rows=1 width=92)   InitPlan    ->  Result
(cost=0.00..0.00rows=0 width=0) 
 

This is the result in my current environment.
Hmm,what's the difference between 1) and 2) ?

Regards.

Hiroshi Inoue


pgsql-hackers by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: Patch for TNS services
Next
From: Jules Bean
Date:
Subject: Re: Performance on inserts