Re: Function query efficiency and optimization

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dan Castido <dan(dot)castido(at)yahoo(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Function query efficiency and optimization
Date: 2011-03-08 17:50:44
Message-ID: 22793.1299606644@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Dan Castido <dan(dot)castido(at)yahoo(dot)com> writes:
> Hi.
> Assuming I have a function like:

> CREATE FUNCTION f () RETURNS SETOF INTEGER LANGUAGE PLPgSQL AS
> $$
> BEGIN
> RETURN QUERY SELECT * FROM t;
> END;
> $$;

> And I call:

> SELECT * FROM f LIMIT 10;

> Is Postgres smart enough to ensure that the function won't do a full scan of the table and then discard all but ten results?

No, not with plpgsql. I think the equivalent construct with a
plain-SQL-language function might behave the way you want.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Craig Barnes 2011-03-08 20:58:27 Re: Simple table creation
Previous Message Dan Castido 2011-03-08 17:00:25 Function query efficiency and optimization