-->
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: Select max(time) Slow when 0 entries exist
PostPosted: Mon Sep 03, 2012 6:53 pm 
Newbie

Joined: Mon Sep 03, 2012 6:26 pm
Posts: 1
This is my first time posting, so please let me know if I am missing anything vital or required in my post. And, thanks in advance!

Overview
I am working on a project where we are using Java 1.6, Hibernate 3, and an Oracle 10g database.

There is a very large table with >200 million rows, that is indexed by Time, UniqueIdentifier, and several other columns frequently used for access.

There are many entries for a given UniqueIdentifier at different Times. Here is the raw SQL for the query we are having issues with:
Code:
select * from Table
where Time = (select max(Time) from Table where UniqueIdentifier='value')
and UniqueIdentifier='value'

As you can see, our goal is to retrieve the most recent record for a particular UniqueIdentifier.

The Issue
When directly logged into the Oracle DB, this SQL query takes <1 sec to return in all cases. When issued via Hibernate using .createSQLQuery(), or createQuery(), or createCriteria() the query also takes <1 sec to return.

However, when no entry exists in the database for the given UniqueIdentifier, Hibernate takes >10 MINUTES to return, regardless of the method used to generate and issue the query.

I have taken the inner query...
Code:
select max(Time) from Table where UniqueIdentifier='value'

...and issued it as a separate Hibernate query via all of the previously mentioned methods, and found that this is where the bottleneck lies (i.e. it takes >10 MINUTES for this inner query to return).

Any Ideas?
Is there any setting I can tweak in Hibernate, or Oracle, or Java to eliminate this insanely long (and seemingly unnecessary) query time? Or maybe there is a known issue that might cause these symptoms? I'd be happy to post whatever additional information you feel might help in debugging this strange and opaque issue. Many hours wasted on it already. Thank you!


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.