Re: func() & select func()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)jp>
Cc: "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: func() & select func()
Date: 2000-08-31 14:37:20
Message-ID: 1779.967732640@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)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
outer select *should* assume that a parameterless inner select yields
constant results --- if you don't assume that then it makes no sense
to do joins over the results of sub-SELECTs in FROM, which is a feature
required by full SQL...

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ross J. Reedstrom 2000-08-31 14:43:48 Re: Patch for TNS services
Previous Message Tom Lane 2000-08-31 14:19:36 Re: AW: Backend-internal SPI operations