-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problematic SQL query, can it be optimized manually?
PostPosted: Fri Feb 04, 2011 8:02 am 
Newbie

Joined: Fri Feb 04, 2011 7:17 am
Posts: 1
Hi,

I have a "complex/big" SQL query that is rather slow and probably unoptimized. It takes a lot of time for the database to process and return the answer. The tables included in the search are also rather big (> 1 000 000 rows).

For testing I've tried to split up the giant SQL question and run the queries separately, which takes considerably less time. However, databases are usually very good at optimizing queries but either way I thought it was a good idea to ask if there is a way to rephrase the query to speed it up? or some Hibernate specific optimizations that can be done. It's an Oracle database btw.


Code:
session.createQuery("select substr(Loan.branchId,1,2), DeviationHistory.text from Loan as Loan, "
    + "LoanHistory as DeviationHistory, LoanHistory as ToVaultHistory where Loan.id = DeviationHistory.loanId "
    + "and DeviationHistory.loanId = ToVaultHistory.loanId "
    + "and DeviationHistory.description.id = :deviation "
    + "and DeviationHistory.eventDate between :startDate and :endDate "
    + "and ToVaultHistory.description.id = :sent "
    + "and ToVaultHistory.eventDate between :startDate and :endDate");


Regarding indexes for the database, indexing the eventDate column only speeds up the question marginally.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.