Skip site navigation (1) Skip section navigation (2)

func() & select func()

From: "Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)jp>
To: "pgsql-hackers" <pgsql-hackers(at)postgreSQL(dot)org>
Subject: func() & select func()
Date: 2000-08-31 08:10:18
Message-ID: 000901c01322$e6bf81e0$2801007e@tpf.co.jp (view raw or flat)
Thread:
Lists: 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.01
	rows=1 width=92) 

1) Using non-cachable function f()
  =# create function f(oid) returns oid as
    '
     select $1;
    ' language 'sql';
  =# explain select * 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.01
	rows=1 width=92)
    InitPlan
     ->  Result  (cost=0.00..0.00 rows=0 width=0) 

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

Regards.

Hiroshi Inoue

Responses

pgsql-hackers by date

Next:From: Jules BeanDate: 2000-08-31 11:40:42
Subject: Re: Performance on inserts
Previous:From: Thomas LockhartDate: 2000-08-31 05:32:51
Subject: Re: Patch for TNS services

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group