Received: from candle.pha.pa.us (maillist@s5-03.ppp.op.net [209.152.195.67]) by hub.org (8.9.3/8.9.3) with ESMTP id UAA98379 for ; Fri, 29 Oct 1999 20:21:52 -0400 (EDT) (envelope-from maillist@candle.pha.pa.us) Received: (from maillist@localhost) by candle.pha.pa.us (8.9.0/8.9.0) id UAA24998; Fri, 29 Oct 1999 20:19:26 -0400 (EDT) From: Bruce Momjian Message-Id: <199910300019.UAA24998@candle.pha.pa.us> Subject: Re: [SQL] trivial problem In-Reply-To: <3670.941240269@sss.pgh.pa.us> from Tom Lane at "Oct 29, 1999 07:37:49 pm" To: Tom Lane Date: Fri, 29 Oct 1999 20:19:26 -0400 (EDT) CC: Moray McConnachie , tjk@tksoft.com, "Roderick A. Anderson" , oleg@sai.msu.su, pgsql-sql@postgreSQL.org X-Mailer: ELM [version 2.4ME+ PL65 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit > Bruce Momjian writes: > > FAQ says: > > See the fetch manual page, or use SELECT ... LIMIT....

> > > This only prevents all row results from being transferred to the client. > > The entire query must be evaluated, even if you only want just the first > > few rows. Consider a query that has an order by. There is no way > > to return any rows until the entire query is evaluated and sorted.

> > That FAQ entry is not right. It might be right for FETCH, but not for > SELECT ... LIMIT. With a LIMIT, the executor will stop once it has > generated the requested number of rows. Of course, how much computation > is needed to reach that point depends greatly on the query and the query > plan. New FAQ text is: The entire query may have to be evaluated, even if you only want the first few rows. Consider a query that has an ORDER BY. If there is an index that matches the ORDER BY, PostgreSQL may be able to evaluate only the first few records requested, or the entire query may have to be evaluated until the desired rows have been generated. -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026