pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: soni de <soni.de@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Takes too long to fetch the data from database
Date: Fri, 21 Apr 2006 09:44:25 -0400
Message-ID: <b42b73150604210644x4f3857f3u9eecbcad8402351d@mail.gmail.com> (raw)
In-Reply-To: <9f2e40a90604202142x5adbe6f0r7a993f8319619cc7@mail.gmail.com>
References: <9f2e40a90604100021n1cb694d0lb95f318f800f33ee@mail.gmail.com>
	<b42b73150604100845w553dcee6kde20e4b82770aab0@mail.gmail.com>
	<9f2e40a90604110004u787716c2s22bdf53fe349326@mail.gmail.com>
	<b42b73150604110613h2c63ea61oec8035c8e2f4ed98@mail.gmail.com>
	<9f2e40a90604192237i5d3e8f0dl1c8b19887bc34e22@mail.gmail.com>
	<b42b73150604200905h56a0d387xec8c80b4c8d3e901@mail.gmail.com>
	<9f2e40a90604202142x5adbe6f0r7a993f8319619cc7@mail.gmail.com>

On 4/21/06, soni de <soni.de@gmail.com> wrote:
>
> I don't want to query exactly 81900 rows into set. I just want to fetch 50
> 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 must do:

1st 50:
select * from t order by j, k limit 50;
2nd 50:
select * from t where j >= j1 and (j > j1 or k > k1) order by j, k limit 50;
3 fields:
select * from t where i >= i1 and (i > i1 or j >= 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;



view thread (17+ messages)  latest in thread

Message-ID: <b42b73150604210644x4f3857f3u9eecbcad8402351d@mail.gmail.com>
Permalink:  ../b42b73150604210644x4f3857f3u9eecbcad8402351d@mail.gmail.com/
Also on:    postgresql.org/message-id/b42b73150604210644x4f3857f3u9eecbcad8402351d@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: mmoncure@gmail.com, soni.de@gmail.com
  Subject: Re: Takes too long to fetch the data from database
  In-Reply-To: <b42b73150604210644x4f3857f3u9eecbcad8402351d@mail.gmail.com>
  References: <9f2e40a90604100021n1cb694d0lb95f318f800f33ee@mail.gmail.com> <b42b73150604100845w553dcee6kde20e4b82770aab0@mail.gmail.com> <9f2e40a90604110004u787716c2s22bdf53fe349326@mail.gmail.com> <b42b73150604110613h2c63ea61oec8035c8e2f4ed98@mail.gmail.com> <9f2e40a90604192237i5d3e8f0dl1c8b19887bc34e22@mail.gmail.com> <b42b73150604200905h56a0d387xec8c80b4c8d3e901@mail.gmail.com> <9f2e40a90604202142x5adbe6f0r7a993f8319619cc7@mail.gmail.com> <b42b73150604210644x4f3857f3u9eecbcad8402351d@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox