-->
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: Join style -- join on vs theta
PostPosted: Tue Nov 25, 2003 2:36 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I noticed that a query I am running is using a theta style join. It will likely run faster with standard join syntax. In this case it is fast enough, but I was wondering how the decision is made. Here is a piece of the mapping:

<property column="RGN" length="5" name="regionId" not-null="true" insert="false" update="false" type="string" />
...
<many-to-one name="destination" class="com.bla.Destination" not-null="true">
<column name="RGN" />
<column name="DST" />
</many-to-one>

The HQL has something like: Select MyClass from MyClass as MyClass where MyClass.regionId = 1 and MyClass.destination.region.regionId = 1 and MyClass.destination.customer.customerId = 2

This gives all destinations for a customer within a region. It generates something like:

where (transact0_.RGN=1 )and(destinat1_.RGN=1 and transact0_.RGN=destinat1_.RGN and transact0_.DST=destinat1_.DST)and(destinat1_.CST=2 and transact0_.RGN=destinat1_.RGN and transact0_.DST=destinat1_.DST)

This could be written as:

MyClass transact0)_ join Destination destinat1_ on transact0_.RGN=destinat1_.RGN and transact0_.DST=destinat1_.DST where transact0_RGN=1 and destinat1_.CST=2

Or likely to be faster:

MyClass transact0)_ join Destination destinat1_ on transact0_.RGN=destinat1_.RGN and transact0_.DST=destinat1_.DST and destinat1_.CST=2 where transact0_RGN=1

It would be nice to be able to give hints in the HQL. With DB2 or Oracle you have the ability to provide hints to do things like force join order, optimize to first read, etc. Will the AST parser provide a better foundation for this sort of support?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 8:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
implicit joins in the where clause result in theta joins (because they could possibly appear inside parentheses).

Don't use implicit joins and you will be fine.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 3:22 am 
Regular
Regular

Joined: Tue Sep 02, 2003 5:09 pm
Posts: 81
Location: Whitefish Montana
I can't come up with any way to write this without the implicit join. The customerId is not an identity stored on the primary table. Any hints?

I guess I haven't hit the right case but I don't understand how parenthesis in the where clause can override the join criteria found in the mapping. I was going on the assumption that the join criteria in the mapping is always at a higher level than the where clause.


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.