X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B263A11F68C6 for ; Fri, 21 Apr 2006 10:44:31 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.092 X-Spam-Level: X-Spam-Status: No, score=0.092 required=5 tests=[AWL=0.092] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id ApVzVGhLqn9S for ; Fri, 21 Apr 2006 10:44:23 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.202]) by postgresql.org (Postfix) with ESMTP id B9BCF11F6756 for ; Fri, 21 Apr 2006 10:44:26 -0300 (ADT) Received: by nz-out-0102.google.com with SMTP id 9so371425nzo for ; Fri, 21 Apr 2006 06:44:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=aVlg/U/GVwP7RFWRlFalsyEaB3Ko7BCjEuwI1oCoTisxa76KSrwhm++g0QBY65G6BoYJcJBXk4SKRk0kWUjiiHjT70dtXWkMGobdT7+ulmFRi7zR21L9S7/kQAzVdDUBK/+X98bjXADxufyPvacnCr/UjuG5Ipfp7G0uszNLFMc= Received: by 10.65.243.20 with SMTP id v20mr1028269qbr; Fri, 21 Apr 2006 06:44:25 -0700 (PDT) Received: by 10.65.137.8 with HTTP; Fri, 21 Apr 2006 06:44:25 -0700 (PDT) Message-ID: Date: Fri, 21 Apr 2006 09:44:25 -0400 From: "Merlin Moncure" To: "soni de" Subject: Re: Takes too long to fetch the data from database Cc: pgsql-performance@postgresql.org In-Reply-To: <9f2e40a90604202142x5adbe6f0r7a993f8319619cc7@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <9f2e40a90604100021n1cb694d0lb95f318f800f33ee@mail.gmail.com> <9f2e40a90604110004u787716c2s22bdf53fe349326@mail.gmail.com> <9f2e40a90604192237i5d3e8f0dl1c8b19887bc34e22@mail.gmail.com> <9f2e40a90604202142x5adbe6f0r7a993f8319619cc7@mail.gmail.com> X-Archive-Number: 200604/501 X-Sequence-Number: 18585 On 4/21/06, soni de wrote: > > I don't want to query exactly 81900 rows into set. I just want to fetch 5= 0 > or 100 rows at a time in a decreasing order of stime.(i.e 50 or 100 rows > starting from last to end). aha! you need to implement a 'sliding window' query. simplest is when you are ordering one field that is unique: 1st 50: select * from t order by k limit 50; 2nd 50: select * from t where k > k1 order by k limit 50: if you are ordering on two fields or on a field that is not unique, you mus= t do: 1st 50: select * from t order by j, k limit 50; 2nd 50: select * from t where j >=3D j1 and (j > j1 or k > k1) order by j, k limit = 50; 3 fields: select * from t where i >=3D i1 and (i > i1 or j >=3D j1) and (i > i1 or j > k1 or k > k1) order by i,j,k limit 50; i1,j1,k1 are the values of the 50th record you pulled out of the last query= . if this seems a little complicated, either wait for pg 8.2 or get cvs tip and rewrite as: select * from t where (i,j,k) > (i1,j1,k1) order by i,j,k limit 50;