Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 1261B476C02 for ; Thu, 20 Jun 2002 12:12:29 -0400 (EDT) Received: from candle.pha.pa.us (216-55-132-35.dsl.san-diego.abac.net [216.55.132.35]) by postgresql.org (Postfix) with ESMTP id A065947694E for ; Thu, 20 Jun 2002 12:11:13 -0400 (EDT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id g5KGAm507411; Thu, 20 Jun 2002 12:10:48 -0400 (EDT) From: Bruce Momjian Message-Id: <200206201610.g5KGAm507411@candle.pha.pa.us> Subject: Re: Which one is faster? In-Reply-To: <3D11C92E.F05D0E80@Yahoo.com> To: Jan Wieck Date: Thu, 20 Jun 2002 12:10:48 -0400 (EDT) Cc: Wei Weng , pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL97 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200206/277 X-Sequence-Number: 8242 Jan Wieck wrote: > Bruce Momjian wrote: > > > > Wei Weng wrote: > > > Between Using Limit P, S or using a cursor to start from FETCH ABSOLUTE > > > S and FETCH NEXT for P times, which one is faster? > > > > LIMIT is faster because it doesn't need to generate all the result, in > > some cases. > > Neither does using a cursor need to generate all the results first. It's > a portal, which is an executor state on hold, and FETCH is implemented > as ExecutorRun() with the number of wanted result rows as limitation. > Since LIMIT generates internally one more result row than really wanted, > I don't think LIMIT would be much faster, but it's for sure less > portable. Oh, I thought the portal had to be materialized before returning a row. Thanks. -- Bruce Momjian | http://candle.pha.pa.us pgman@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