-->
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: HQL Performance
PostPosted: Tue Jul 28, 2009 11:13 am 
Newbie

Joined: Thu Apr 24, 2008 7:43 pm
Posts: 6
Is there a difference in performance of HQL if you select individual columns vs selecting a whole object? When I use HQL to select a whole object the query takes about 7 min to run (table has about 5k records in it). If I explicitly define the columns the query runs in about 5 seconds.

HQL that takes 7min
Code:
getHibernateTemplate().find(
"select l from Location l inner join fetch l.city city inner join fetch l.city city left outer join fetch city.cityVariations cityVariations left join fetch l.state state inner join fetch l.country country order by l.locationTitleSourceText");


HQL take takes 5 seconds.
Code:
getHibernateTemplate().find("select l.id,l.eoag, l.oag,l.website, l.email,l.actualCityName,l.locationTitleSourceText, l.address2,l.address3,l.address4,l.address5, l.zipCode, country.countryCode, state.stateSourceText, city.destinationCityNameSourceText from Location l order by l.locationTitleSourceText");


I know that there is some joins in the first but not in the second, but even if I take out all the joins (inner and outer) it does not change the execution time of the query.


hbm
Code:
<class name="Location" table="db2inst1.LocLocations" >
<id name="id" column="Id" type="long">
  <generator class="native" />
  </id>
 
  <property name="eoag" column="EoagCode" not-null="true" length="6" index="eoag_index" unique-key="CompositeUniqueKey"/>
  <property name="brand" column="brand" not-null="true" length="25" unique-key="CompositeUniqueKey"/>
  <property name="oag" column="OagCode" length="3" index="oag_index"/>
  <property name="zipCode" column="ZipCode" not-null="false" length="30"/>
  <property name="locationType" column="LocationType" not-null="true" length="1"/>
  <property name="website" column="Website" length="75" not-null="false"/>
  <property name="email" column="Email"  length="75"/>

  <many-to-one name="state" column="LocStateId" class="State" fetch="join"  lazy="false"  />
  <many-to-one name="country" column="LocCountryId" class="Country" fetch="join"   unique="false" lazy="false" not-null="true" />
  <many-to-one name="serviceLocation" column="LocLocationServiceId" class="Location" fetch="join"   />
  <many-to-one name="afterHoursLocation" column="LocLocationAfterHoursId" class="Location" fetch="join"   />
  <many-to-one name="city" column="LocCityId" class="City" fetch="join" lazy="false"   not-null="true" />
  <property name="actualCityName" column="ActualCityName" length="255"/>
  <map name="phoneMap"  cascade="all,delete-orphan" inverse="true" >
   <key column="LocLocationId"/>
   <index column="PhoneType" type="string"></index>
   <one-to-many class="LocationPhone"/>
</map>

  <property name="fee" column="Fee" type="double" length="4" precision="2"/>
  <property name="formerlyKnownAs" column="LocationFormlyKnownAs" length="255"/>
  <property name="address2" column="Address2" index="address2" length="255"/>
  <property name="address3" column="Address3" index="address3" length="255"/>
  <property name="address4" column="Address4" length="255"/>
  <property name="address5" column="Address5" length="255"/>
  <property name="locationTitleSourceText" column="LocationTitle" index="location_title_index" not-null="true" length="255"/>
  <property name="majorAirport" column="MajorAirport" type="boolean" not-null="true"/>
  <property name="locationNotes" column="Notes" type="text" length="5000" />
  <property name="locationLandMarkDetails" column="locationLandMarkDetails" type="text" length="500" />
 
</class>


Top
 Profile  
 
 Post subject: Re: HQL Performance
PostPosted: Sat Aug 01, 2009 6:59 pm 
Newbie

Joined: Tue Jul 14, 2009 2:16 pm
Posts: 6
I am very interested in this too. Anyone?


Top
 Profile  
 
 Post subject: Re: HQL Performance
PostPosted: Tue Aug 04, 2009 9:49 am 
Newbie

Joined: Thu Apr 24, 2008 7:43 pm
Posts: 6
I came across this article and was wondering what the hibernate community thought of the problem. It talks about selecting columns vs loading whole objects.

http://stackoverflow.com/questions/291853/why-is-orm-considered-good-but-select-considered-bad


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.