-->
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.  [ 3 posts ] 
Author Message
 Post subject: Huge query takes too long 1st time executed, workarounds?
PostPosted: Thu Apr 03, 2008 8:43 am 
Beginner
Beginner

Joined: Mon Apr 02, 2007 8:08 am
Posts: 24
I have a huge query (10 A4 sheets if you print it) which returns 3 rows. If you open it with SQLPlus (Oracle) the first time you run it takes ~3 minutes to run. The 2nd time, just 8 miliseconds. My DBA is tracing it and he thinks the problem is not the query itself (few data, right use of indexes and so on) but the parsing and execution plan calculation. If you do a trivial change at the query it will take 3 minutes again, so that's likely to be the reason.

How can I deal with this?

_________________
--
<a href="http://ideasse.blogspot.com/">Ideas + Software Engineering</a> (English)
<a href="http://iiso.blogspot.com/">Ideas + IngenierĂ­a del Software</a> (Spanish)


Top
 Profile  
 
 Post subject: Re: Huge query takes too long 1st time executed, workarounds
PostPosted: Thu Apr 03, 2008 10:25 am 
Newbie

Joined: Thu Apr 03, 2008 9:33 am
Posts: 2
10 A4 sheets is quiet a huge query, most of the time when there is use of multiple joins on the same table the cost of the query starts increasing steeply, try breaking up the query/where clauses in to chunks, one way is by using projections on your PK column and use these ids in where condition to get the list of ids, repeat this till all your conditions are executed...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 10:35 am 
Beginner
Beginner

Joined: Mon Apr 02, 2007 8:08 am
Posts: 24
In fact there's no where clause. The joins are done with LEFT OUTER JOIN due to *ToOne eager associations. Maybe the only actual sollution will be reducing the number of EAGER relationships.

I have a quite big application (+100 tables) and this is the first time I face this problem. I think the most conflictive part is a polimorphic association. I have an A class with has a @OneToOne relationship to a AbstractB class. AbstractB inheritance tree is implemented with join classes strategy (in order to support polimorphism). I have around 6 classes (let's call them B1, B2 .. B6) which extends AbtractB, and when you do a.getB() at the code it implies 6 left outer joins (one for each concrete table) plus the joins of every eager relationship B* classes have.

It seems not being expensive tn terms of data (there're not much rows) or table joining (every join can use an index, so cost is constant) but of query complexity. Oracle takes too much time analyzing the way he'll run the query...

_________________
--
<a href="http://ideasse.blogspot.com/">Ideas + Software Engineering</a> (English)
<a href="http://iiso.blogspot.com/">Ideas + IngenierĂ­a del Software</a> (Spanish)


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

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.