pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ragnar Hafstaư <gnari@simnet.is>
To: Joel Fradkin <jfradkin@wazagua.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: getting count for a specific querry
Date: Fri, 08 Apr 2005 16:25:46 +0000
Message-ID: <1112977546.7447.39.camel@localhost.localdomain> (raw)
In-Reply-To: <000001c53c3e$f4f5b730$797ba8c0@jfradkin>
References: <000001c53c3e$f4f5b730$797ba8c0@jfradkin>

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






view thread (38+ messages)  latest in thread

Message-ID: <1112977546.7447.39.camel@localhost.localdomain>
Permalink:  ../1112977546.7447.39.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1112977546.7447.39.camel@localhost.localdomain

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gnari@simnet.is, jfradkin@wazagua.com
  Subject: Re: getting count for a specific querry
  In-Reply-To: <1112977546.7447.39.camel@localhost.localdomain>

* 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