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

From Hiroshi Inoue
Subject RE: func() & select func()
Date
Msg-id 000501c013bd$7d66a700$2801007e@tpf.co.jp
Whole thread Raw
In response to Re: func() & select func()  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: func() & select func()
List pgsql-hackers
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> 
> "Hiroshi Inoue" <Inoue@tpf.co.jp> writes:
> > 1) Using non-cachable function f()
> >   =# explain select * from pg_class where oid=f(1259);
> >   Seq Scan on pg_class  (cost=0.00..3.17 rows=1 width=92) 
> 
> > 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) 
> 
> The sub-select is reduced to an initplan --- ie, executed only once,
> not once per row --- because it has no dependency on the outer select.
> 
> Currently we do not consider the presence of noncachable functions as
> a reason that prevents reducing a subplan to an initplan.  I thought
> about it but didn't like the performance penalty.  It seems to me that
> it's debatable which is the correct semantics, anyway.  Arguably an

After a little thought,it seems to me that the behavior of the subquery
is more reasonable than current evaluation of functions.

Under MVCC,SELECT returns the content of a database at the time
when the query started no matter how long time it takes to return
the resultset.
Shouldn't functions be evaluated once(per the combination of parameters)
at the time when a query started ?

Regards.

Hiroshi Inoue


pgsql-hackers by date:

Previous
From: Jan Wieck
Date:
Subject: Re: Backend-internal SPI operations
Next
From: Tom Lane
Date:
Subject: Re: func() & select func()