Re: getting count for a specific querry

From: PFC <lists(at)boutiquenumerique(dot)com>
To: "Joel Fradkin" <jfradkin(at)wazagua(dot)com>, "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "'Bob Henkel'" <luckyratfoot(at)gmail(dot)com>
Cc: "'Scott Marlowe'" <smarlowe(at)g2switchworks(dot)com>, "'Andrew Sullivan'" <ajs(at)crankycanuck(dot)ca>, pgsql-sql(at)postgresql(dot)org
Subject: Re: getting count for a specific querry
Date: 2005-04-08 21:37:55
Message-ID: op.soxnphy2th1vuj@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> Since it is a count of matched condition records I may not have a way
> around.

What you could do is cache the search results (just caching the id's of
the rows to display is enough and uses little space) in a cache table,
numbering them with your sort order using a temporary sequence, so that
you can :
SELECT ... FROM cache WHERE row_position BETWEEN page_no*per_page AND
(page_no+1)*per_page-1
to get the count :
SELECT row_position FROM CACHE ORDER BY row_position DESC LIMIT 1

Add a session_id referencing your sessions table with an ON DELETE
CASCADE and the cache will be auto-purged when sessions expire.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message PFC 2005-04-08 22:15:46 Re: getting count for a specific querry
Previous Message Joel Fradkin 2005-04-08 21:09:21 Re: getting count for a specific querry