X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5D68A3A4894; Thu, 20 Jan 2005 19:22:13 +0000 (GMT) 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 63381-08; Thu, 20 Jan 2005 19:22:07 +0000 (GMT) Received: from quasar.skima.is (quasar.skima.is [212.30.200.205]) by svr1.postgresql.org (Postfix) with ESMTP id 4E0153A491C; Thu, 20 Jan 2005 19:21:55 +0000 (GMT) Received: from gnari ([157.157.193.37] [157.157.193.37]) by quasar.skima.is with ESMTP; Thu, 20 Jan 2005 19:21:55 Z Subject: Re: [SQL] OFFSET impact on Performance??? From: Ragnar =?ISO-8859-1?Q?Hafsta=F0?= To: pgsql-performance@postgresql.org Cc: Andrei Bintintan , pgsql-sql@postgresql.org In-Reply-To: <1106248326.22416.22.camel@localhost.localdomain> References: <019f01c4fee1$1b58d600$0b00a8c0@forge> <41EF9FD3.5020400@archonet.com> <020d01c4fef6$595bb9d0$0b00a8c0@forge> <87pt00c9zd.fsf@stark.xeocode.com> <1106248326.22416.22.camel@localhost.localdomain> Content-Type: text/plain; charset=iso-8859-1 Date: Thu, 20 Jan 2005 19:23:12 +0000 Message-Id: <1106248992.22416.25.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200501/333 X-Sequence-Number: 10023 On Thu, 2005-01-20 at 19:12 +0000, Ragnar Hafstaš wrote: > On Thu, 2005-01-20 at 11:59 -0500, Greg Stark wrote: > > > The best way to do pages for is not to use offset or cursors but to use an > > index. This only works if you can enumerate all the sort orders the > > application might be using and can have an index on each of them. > > > > To do this the query would look something like: > > > > SELECT * FROM tab WHERE col > ? ORDER BY col LIMIT 50 > > > > Then you take note of the last value used on a given page and if the user > > selects "next" you pass that as the starting point for the next page. > > this will only work unchanged if the index is unique. imagine , for > example if you have more than 50 rows with the same value of col. > > one way to fix this is to use ORDER BY col,oid and a slightly more complex WHERE clause as well, of course gnari