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 QAA61782 for ; Fri, 29 Oct 1999 16:22:51 -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 QAA07363; Fri, 29 Oct 1999 16:19:57 -0400 (EDT) From: Bruce Momjian Message-Id: <199910292019.QAA07363@candle.pha.pa.us> Subject: Re: [SQL] trivial problem In-Reply-To: <003101bf2248$76e0d8e0$9f1b4cc0@public.ox.ac.uk> from Moray McConnachie at "Oct 29, 1999 09:02:00 pm" To: Moray McConnachie Date: Fri, 29 Oct 1999 16:19:57 -0400 (EDT) CC: 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 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.

[Charset iso-8859-1 unsupported, filtering to ASCII...] > > ----- Original Message ----- > From: > To: Roderick A. Anderson > Cc: ; > Sent: Friday, October 29, 1999 7:12 PM > Subject: Re: [SQL] trivial problem > > > > If limit didn't mean "get first 50," there would be no time/effort > > saved by specifying a limit. > > > > I.e. when a limit is specified, the backend looks for matches until it > > finds 50 records, and then stops. > > Eh? I think the questioner meant effectively "in a query with LIMIT and > ORDER BY, which takes precedence?". To which the answer appears to be ORDER > BY, which surprised me, but is of course very useful. > > I.e. all sorting is completed, and then the first fifty records are > returned. > > Does that mean that the seek time for a limited, ordered by query is the > same as that for an unlimited query? The extra speed gained from the limit > only achieved by not having to return the data? Or is there some kind of > magic going on to allow it to ignore certain things about the query when a > LIMIT is in place? > > > ************ > > -- 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