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.  [ 4 posts ] 
Author Message
 Post subject: Query on associations whitout join ?
PostPosted: Thu Aug 17, 2006 5:27 am 
Newbie

Joined: Thu Aug 17, 2006 5:10 am
Posts: 3
Hi all

I'm using SQLServer 2005.

I've two tables with a simple one-to-many relationship (Document 1=> n Files)

I d'like to retrieve every document that have a file named "test.txt" or in sql form

Code:
SELECT * FROM Documents,Files
WHERE Documents.DocumentId = Files.DocumentId
AND Files.Name = "test.txt"


I'm able to retrieve the values using that ICriteria based code:

Code:
ICriteria criteria = session.CreateCriteria(typeof(Document));
criteria.CreateAlias("Files", "files");
criteria.Add(NHibernate.Expression.Expression.Eq("files.Name","test.txt"));
criteria.List();


But that Criteria generate that kind of query :

Code:
SELECT
this.DocumentId as DocumentId1_,
this.ModifiedBy as ModifiedBy1_,
this.LastUpdateDate as LastUpda4_1_,
this.CreationDate as Creation3_1_,
this.RetentionDate as Retentio2_1_,
files.fileId as FileId0_,
files.DocumentId as DocumentId0_,
files.Name as Files0_,
files.ModifiedBy as ModifiedBy0_,
files.CreationDate as Creation3_0_,
files.LastUpdateDate as LastUpda4_0_
FROM Documents this inner join Files files on this.DocumentId=files.DocumentId
WHERE files.Name = 'test.txt'


That query returns me the good values but it MUCH slower that the first one (about 10 times slower (tests using SQL Manager))!

I'm certainly missing something here, sorry if it seems too obvious.

Thanks for help


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 6:54 am 
Newbie

Joined: Thu Aug 17, 2006 5:10 am
Posts: 3
Hum after some more testing, it seems that there is no big speed difference between join or not-join (Haa forgot about cache :)).

I still have another question

How did you write that query using HQL ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 8:13 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
tropico wrote:
Hum after some more testing, it seems that there is no big speed difference between join or not-join (Haa forgot about cache :)).

I still have another question

How did you write that query using HQL ?

Thanks


What is the speed if You inverse the join? I.e.
Code:
SELECT
this.*
FROM Files files
inner join Documents this on this.DocumentId=files.DocumentId
WHERE files.Name = 'test.txt'


In some RDBMS, the cartesian join (Your faster example) is EXTREMLY slow, if the tables do contain much data.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 8:50 am 
Newbie

Joined: Thu Aug 17, 2006 5:10 am
Posts: 3
It takes the same time as the others.

about 15-16 seconds the first time, less after (cache).

My table contains a lot of entries (~2.500.000)

any idea for the HQL equivalent ?

Tks for answer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.