X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4145153635 for ; Fri, 8 Apr 2005 17:24:20 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69955-01 for ; Fri, 8 Apr 2005 16:24:15 +0000 (GMT) Received: from quasar.skima.is (quasar.skima.is [212.30.200.205]) by svr1.postgresql.org (Postfix) with ESMTP id 9E2D453671 for ; Fri, 8 Apr 2005 17:24:14 +0100 (BST) Received: from gnari ([157.157.159.208] [157.157.159.208]) by quasar.skima.is with ESMTP; Fri, 8 Apr 2005 16:24:14 Z Subject: Re: getting count for a specific querry From: Ragnar =?ISO-8859-1?Q?Hafsta=F0?= To: Joel Fradkin Cc: pgsql-sql@postgresql.org In-Reply-To: <000001c53c3e$f4f5b730$797ba8c0@jfradkin> References: <000001c53c3e$f4f5b730$797ba8c0@jfradkin> Content-Type: text/plain Date: Fri, 08 Apr 2005 16:25:46 +0000 Message-Id: <1112977546.7447.39.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/97 X-Sequence-Number: 20990 On Fri, 2005-04-08 at 09:29 -0400, Joel Fradkin wrote: > Our app currently pulls a bunch of data to several query pages. > > My idea is to use the limit and offset to return just the first 50 > records, if they hit next I can set the offset. > > My understanding was this gets slower as you move further into the > data, but we have several options to modify the search, and I do not > believe our clients will page very far intro a dataset. you might reduce the performance loss if your dataset is ordered by a UNIQUE index. select * from mytable where somecondition ORDER by uniquecol limit 50; and next: select * from mytable where somecondition AND uniquecol>? ORDER by uniquecol limit 50 OFFSET 50; where the ? is placeholder for last value returned by last query. if your unique index is a multi-column one, the method is slightly more complicated, but the same idea. gnari