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?
|