Function query efficiency and optimization

From: Dan Castido <dan(dot)castido(at)yahoo(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Function query efficiency and optimization
Date: 2011-03-08 17:00:25
Message-ID: 650049.11800.qm@web24812.mail.ird.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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?

I'm trying to work out if i can structure things so that i can reuse most of the functions for different queries by progressively layering limits, offsets, etc.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2011-03-08 17:50:44 Re: Function query efficiency and optimization
Previous Message Dan Castido 2011-03-08 16:56:40