At Devoxx some guys are selling a product that compiles some flavor of
OQL into SQL and have optimized the case of deep hierarchies mapped as
table per subclass (AFAIR).
In some case it has quite dramatic effects. They happened to have
miscoded their HQL query by using inner joins instead of left outer
joins in a few critical places but I don't think that accounts for all
optimizations.
They do seem to pay careful attention to the list elements
returned by the select clause and remove unnecessary joins based on
that.
Here is their more dramatic example
http://fastoql.com/oql_vs_hql.html
We might be able to find a couple of optimization to reuse.
Emmanuel