Running queries to fetch a count of hits in DB on several things - Mailing list pgsql-general

From Mohamed
Subject Running queries to fetch a count of hits in DB on several things
Date
Msg-id 861fed220901160941v478bec2eq724a249f114416d2@mail.gmail.com
Whole thread Raw
Responses Running queries to fetch a count of hits in DB on several things  (Brendan Duddridge <brendan@clickspace.com>)
List pgsql-general
Hi, this is basically what I would like to improve : 

1) A user searches for a product on category and location. 

a) The query is run and the result (limit 30) are returned and shown.
b) The same query is ran again but now I return the count on how many matches there was totally. (This has to be possible to include somehow in the above, without the limit it would return all rows and therefor the number of matches as well)
c) The same query is ran again but now I return the count on how many matches there was in each location
c)  --- " " --- count on category.
d) --- " " ---  count on how many that was used or new. 
etc...


How can I improve this? Seems so unnecessary to have to run the query on every count I want to do when its the same query hitting the same relation with a slight modification in each? Is there a way or should I just forget about it and run them over and over again? I am guessing using functions could be possible but now so little about them and how to run them from Java. There might be 1000 or more users on the website simultaneously and I am guessing this could be a real downside...

Thanks / Moe





























pgsql-general by date:

Previous
From: David Fetter
Date:
Subject: Re: [HACKERS] Question regarding new windowing functions in 8.4devel
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Question regarding new windowing functions in 8.4devel