Re: getting count for a specific querry

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ragnar Hafstað <gnari(at)simnet(dot)is>
Cc: Joel Fradkin <jfradkin(at)wazagua(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: getting count for a specific querry
Date: 2005-04-08 16:32:03
Message-ID: 15084.1112977923@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Ragnar =?ISO-8859-1?Q?Hafsta=F0?= <gnari(at)simnet(dot)is> writes:
> 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.

Uh, you don't want the OFFSET there do you? But otherwise, yeah,
this is a popular solution for paging through some rows. Doesn't really
help with the problem of counting the total dataset though ...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Rod Taylor 2005-04-08 16:51:32 Re: getting count for a specific querry
Previous Message Andrew Sullivan 2005-04-08 16:30:39 Re: getting count for a specific querry