• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another way to get the information needed

 
jess tan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a database that is being constantly updated and a program that constantly reads data from the database and calculates a result(by counting how many rows in the column has NameA and how many rows in another column has NameB, adding them up and then divide with the total number of rows that the user has posted for a particular topic) and the result would be updated into a column in the database. The problem is that it takes too long for the program to run as it have to search the whole database to update a particular row everytime.

Would like to enquire if anyone have any ideas of another way to retrieve the result needed?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the database have indexes on the relevant columns? This shouldn't be slow at all, if you're doing it right. What do you mean by "counting it up?" Are you using COUNT() in your SQL?
 
jess tan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have placed indexes on the relevant columns.

Yes, I am using count() in my SQL as need to count the number of rows with that particular username.
 
Stephan Mueller
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might consider using a View providing your count-data and select from it.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless it is a materialized view this is unlikely to make much difference if the query itself is slow.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic