-->
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: How does Hibernate determine table ordering in FROM clause?
PostPosted: Tue Nov 30, 2010 7:35 pm 
Beginner
Beginner

Joined: Fri Mar 26, 2010 11:55 am
Posts: 20
I'm examining Hibernate-generated SQL statements for performance tuning purposes, and would like to know whether it is possible to influence Hibernate to choose a particular ordering of tables in the FROM clause.

A known optimization for Oracle and other databases that use cost-based optimization is to manipulate the ordering of tables in the FROM clause. This can influence the query plan in cases where the optimizer doesn't know which ordering is best, resulting in much improved query times.

Hibernate-generated queries are seemingly random in the ordering of tables. For instance, Hibernate might generate this WHERE clause:
SELECT ...
FROM t1
INNER JOIN t2 ON t1.a=t2.a
INNER JOIN t3 ON t1.b=t3.b


However, we might know that due to indexing, etc., a much better ordering would be one where t3 appears earlier than t2, e.g.:
SELECT ...
FROM t1
INNER JOIN t3 ON t1.b=t3.b
INNER JOIN t2 ON t1.a=t2.a


Likewise, Hibernate also seems to mix the ordering of INNER JOIN and LEFT OUTER JOINs, sometimes placing LOJs in front of IJs, even in cases where it's not necessary for correctness.

Is there any way to influence Hibernate to change the table ordering? How does it decide in the first place?


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.