Re: Function query efficiency and optimization - Mailing list pgsql-novice

From Tom Lane
Subject Re: Function query efficiency and optimization
Date
Msg-id 22793.1299606644@sss.pgh.pa.us
Whole thread Raw
In response to Function query efficiency and optimization  (Dan Castido <dan.castido@yahoo.com>)
List pgsql-novice
Dan Castido <dan.castido@yahoo.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

pgsql-novice by date:

Previous
From: Dan Castido
Date:
Subject: Function query efficiency and optimization
Next
From: Craig Barnes
Date:
Subject: Re: Simple table creation