-->
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: eager fetching and postgresql join order performance
PostPosted: Thu May 05, 2005 12:08 pm 
Newbie

Joined: Thu Dec 04, 2003 5:53 am
Posts: 11
Location: Toulouse, France
Hibernate version: 2.1.8

Name and version of the database you are using: Posgresql 7.3.2

Description of problem
In postgresql, using an explicit join order can cause significant performance problems (in my case, 25 seconds instead of 0.2 seconds if the wrong join order is used).
See http://www.postgresql.org/docs/7.4/stat ... joins.html

An explicit join order is unfortunately enforced whenever you use standard inner join syntax:
(1) select a.id, b.id from a inner join b on a.id=b.aid
If you rewrite the query as
(2) select a.id, b.id from a, b where a.id=b.aid
postgresql allows its query planner to do its thing, which is generally the wisest thing to do.

So, what I've been doing is rewriting all of my HQL to look like (2) above. This works for performance. The problem comes with eager fetching.
Since the join is an integral part of the fetch syntax, I see no way to rewrite the HQL to give the planner a free hand at planning.

What I get for the following HQL:

HQL:
SELECT definition.id FROM DefinitionImpl AS definition inner join fetch definition.termesDB AS terme where definition.fiche.id=?

The generated SQL:
select termesdb1_.idTerme as idTerme, termesdb1_.version as version, termesdb1_.idDefinition as idDefini3_, termesdb1_.idEnReponseA as idEnRepo4_, termesdb1_.texte as texte, termesdb1_.textePourTri as textePou6_, termesdb1_.statut as statut, termesdb1_.type as type, termesdb1_.registre as registre, termesdb1_.genre as genre, termesdb1_.idProposePar as idPropo11_, termesdb1_.idRevisePar as idRevis12_, termesdb1_.dateCreation as dateCre13_, termesdb1_.dateMiseAJour as dateMis14_, termesdb1_.idDefinition as idDefini3___, termesdb1_.idTerme as idTerme__, definition0_.idDefinition as x0_0_ from Definition definition0_ inner join Terme termesdb1_ on definition0_.idDefinition=termesdb1_.idDefinition where (definition0_.idFiche=? )

What I would like to get:
select termesdb1_.idTerme as idTerme, termesdb1_.version as version, termesdb1_.idDefinition as idDefini3_, termesdb1_.idEnReponseA as idEnRepo4_, termesdb1_.texte as texte, termesdb1_.textePourTri as textePou6_, termesdb1_.statut as statut, termesdb1_.type as type, termesdb1_.registre as registre, termesdb1_.genre as genre, termesdb1_.idProposePar as idPropo11_, termesdb1_.idRevisePar as idRevis12_, termesdb1_.dateCreation as dateCre13_, termesdb1_.dateMiseAJour as dateMis14_, termesdb1_.idDefinition as idDefini3___, termesdb1_.idTerme as idTerme__, definition0_.idDefinition as x0_0_ from Definition definition0_, Terme termesdb1_ where definition0_.idDefinition=termesdb1_.idDefinition and (definition0_.idFiche=? )

Is there any way to get Hibernate to produce this SQL while benefiting from eager fetching?

Ideally, there could be some Hibernate configuration setting added for the postgresql dialect, which automatically changes all inner joins for all queries to a free syntax, going from a inner join b on a.id=b.aid to a, b where a.id=b.aid

Best regards,
Assaf


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.