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.  [ 6 posts ] 
Author Message
 Post subject: SQL Preview
PostPosted: Tue Feb 26, 2008 12:41 pm 
Newbie

Joined: Wed Jan 31, 2007 5:26 am
Posts: 8
Location: Tel Aviv, Israel
Is there a way to preview the SQL NHibernate generates, without actually running the query.
Something like this:

string sql =
session.CreateCreteria(typeof(Person)).PreviewSQL;


I have a customer asking for this feature,
So he could calculate the sql cost before deciding whether or not to execute the query.

_________________
Tomer Avissar.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 6:36 pm 
Newbie

Joined: Sat Dec 08, 2007 9:22 am
Posts: 10
Have you tried Aydene's query analyzer?

http://www.ayende.com/projects/nhiberna ... lyzer.aspx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 27, 2008 1:13 am 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
Ayende's NHibernate Query Analyzer is for HQL (IQuery) not ICriteria.

My question here is why does your customer want "calculate the sql cost before deciding whether or not to execute the query"? Is it that they don't trust the SQL that NHibernate generates?


Top
 Profile  
 
 Post subject: SQL Preview
PostPosted: Thu Feb 28, 2008 9:34 am 
Newbie

Joined: Wed Jan 31, 2007 5:26 am
Posts: 8
Location: Tel Aviv, Israel
The purpose in this case is to know whether to allow the end user to execute the query. Oracle database has the feature for calculating the cost of a query. They use the Criteria to build a query dynamically. In some cases (usually in the case of join between large tables) they decide not to allow the user to execute the query.

I believe there could be other cases where this could be useful.

_________________
Tomer Avissar.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 10:51 am 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
In Oracle the query cost is relative (to the other possible execution plans for the SQL statement), so I don't think that it's going to help you. However it's been several years since I did any serious Oracle development and things might have changed. I suggest a posting here http://asktom.oracle.com to answer that part of the question.

I know of a trick to extract the SQL for IQuery: http://elegantcode.com/2007/11/16/nhibernate-iquery-to-isqlquery-black-magic/ but I don't know an equivalent for ICriteria (I'm sure there is one if you dig into the internals).

Note that even if you could obtain the SQL to calculate the absolute cost you would still need to submit the SQL to the database engine. So there's going to be two round trips for every query unless you cache the "executability" (and there's enough commonality across queries to justify caching).

I can see the potential need for what you ask but it's very much an edge case. I would be wary about spending a lot of time on this unless you have a concrete (not anticipated) business need (avoid premature optimization!)


Top
 Profile  
 
 Post subject: SQL Preview
PostPosted: Thu Feb 28, 2008 12:07 pm 
Newbie

Joined: Wed Jan 31, 2007 5:26 am
Posts: 8
Location: Tel Aviv, Israel
I can see your point, but it’s hard for me to estimate if there’s indeed a concrete business need. According to my customer, this is a very high scale database and the user is given the option to query every entity in the system, and to cross it (join select) with every other entity. I can assume that by experimenting they hope to find the cost limit in which the system will decline the user query.

Though that may seem as a crazy mechanism, it does seems fairly reasonable to me to allow previewing the query before executing it. There might be some other situations where I can find this helpful. Maybe even in the case of manipulating the query before the execution.

_________________
Tomer Avissar.


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