I have a databas table with cca. 327 000 entries. (SQL Server 2005, Hibernate 3) I have to generate a report that queries this table for 300 times. The Hql query looks like this:
select hist from HistoryTable hist where year(hist.date) = :year and
hist.user.userId = :userId and hist.entryType = :created
I need to wait 3 minutes for the report to be generated, so is there a way to optimize this query to run faster?
I though of returning the hist.id
(because that is a primary key therefore it is indexed and I guess it is looked up faster) instead of the whole hist
object and then retrieve the History
object via its id
? Maybe Hibernate
does the same thing, and this is not neccessary, and then there is nothing to be done. Any ideas?