Running queries to fetch a count of hits in DB on several things

From: Mohamed <mohamed5432154321(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Running queries to fetch a count of hits in DB on several things
Date: 2009-01-16 17:41:32
Message-ID: 861fed220901160941v478bec2eq724a249f114416d2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-01-16 17:41:59 Re: [HACKERS] Question regarding new windowing functions in 8.4devel
Previous Message David Fetter 2009-01-16 17:38:21 Re: [HACKERS] Question regarding new windowing functions in 8.4devel