Re: getting count for a specific querry - Mailing list pgsql-sql

From Ragnar Hafstað
Subject Re: getting count for a specific querry
Date
Msg-id 1112977546.7447.39.camel@localhost.localdomain
Whole thread Raw
In response to getting count for a specific querry  ("Joel Fradkin" <jfradkin@wazagua.com>)
Responses Re: getting count for a specific querry
List pgsql-sql
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





pgsql-sql by date:

Previous
From: Ragnar Hafstað
Date:
Subject: Re: getting count for a specific querry
Next
From: Andrew Sullivan
Date:
Subject: Re: getting count for a specific querry