Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

NH Prof New FeatureThe Query Cache

time to read 2 min | 390 words

Okay, I said it is not there yet, but I got annoyed by the lack of this feature, and I really had to make this work.

That one was a pretty tough one. It required me to make some minor modifications to NHiberante, as a result, this feature works with NHbierante r3976 or up only. What this means is that if you want to use this feature, you have to get it from the trunk.

This is the only feature in NH Prof that requires the trunk.

In this feature, we can see that we detect a cached query, and are able to display it properly.:


I am not sure how I should treat this for the purpose of analysis. Should this be grouped with the actual query? Should this be a separate entry?

Anyway, just for kicks, here is the test for the feature:

public class CachingTestFixture : IntegrationTestBase
    public void CanDetectCachedQueries()

    	var array = observer.Model.Sessions[2].Statements.OfType<StatementModel>()
		Assert.AreEqual(@"Cached query: 
SELECT this_.Id             as Id7_0_,
   this_.Title          as Title7_0_,
   this_.Subtitle       as Subtitle7_0_,
   this_.AllowsComments as AllowsCo4_7_0_,
   this_.CreatedAt      as CreatedAt7_0_
FROM   Blogs this_
WHERE  this_.Title = 'The lazy blog' /* @p0 */
   and this_.Id = 1 /* @p1 */
", array[0].Text);
		Assert.AreEqual(@"Cached query: 
select blog0_.Id             as Id7_,
   blog0_.Title          as Title7_,
   blog0_.Subtitle       as Subtitle7_,
   blog0_.AllowsComments as AllowsCo4_7_,
   blog0_.CreatedAt      as CreatedAt7_
from   Blogs blog0_
where  ( blog0_.Title = 'The lazy blog' /* @p0 */ )
   and ( blog0_.Id = 1 /* @p1 */ )
", array[2].Text);

As an aside, do you think that posting the tests is good? Should I just do the screen shots?

More posts in "NH Prof New Feature" series:

  1. (09 Dec 2010) Alert on bad ‘like’ query
  2. (10 Dec 2009) Filter static files
  3. (16 Nov 2009) Exporting Reports
  4. (08 Oct 2009) NHibernate Search Integration
  5. (19 Aug 2009) Multiple Session Factory Support
  6. (07 Aug 2009) Diffing Sessions
  7. (06 Aug 2009) Capturing DDL
  8. (05 Aug 2009) Detect Cross Thread Session Usage
  9. (22 May 2009) Detecting 2nd cache collection loads
  10. (15 May 2009) Error Detection
  11. (12 May 2009) Queries by Url
  12. (04 Feb 2009) View Query Results
  13. (18 Jan 2009) Superfluous <many-to-one> update
  14. (18 Jan 2009) URL tracking
  15. (10 Jan 2009) Detecting distributed transactions (System.Transactions)
  16. (06 Jan 2009) The Query Cache
  17. (05 Jan 2009) Query Duration
  18. (24 Dec 2008) Unbounded result sets
  19. (24 Dec 2008) Row Counts


Davy Brion

very glad to see this feature as well as the last two that were introduced ;)

i'd leave the tests in these posts... it doesn't hurt anyone and it's interesting to at least some people

Krzysztof Kozmic

I admire your work overall, and with Castle/NHibernate in particular. However I'm not sure I like the idea of changing NHibernate solely to make a 3rd party tool happy.

Tobin Harris

Very nice feature :)

I know this is shrink wrapped software, but how about drawing a feature freeze for this iteration and getting R1 out the door? Then, give us an R2 in 2-4 weeks with more features :)

By the way, I LOVE the fact that you can modify NHibernate to make a feature possible. I see this as an advantage of Open Source software. I realise there's a potential for abuse there too, especially if the modifier benefits financially from the changes.

I also think your NHProf site is looking very concise, and cool. Have you considered linking to the site on each blog post, and also stating that the tool is available for download? (I realised this already, but I want to see a link regardless).

Krzysztof Kozmic


It's not what I feared it would be. You're right, these changes benefit anyone using NHibernate, or at least thehy don't hurt anybody.

What I feared, was that you would start adding changes that would support NHProf, at the expense of making NHibernate less robust, harder to use, add no value for anyone else but NHProf, or hurting it overall in some other way.

Tuna Toksoz

Krzysztof, isn't it the way oss work in general? If you need something, you implement something.

Krzysztof Kozmic


Yes, but you fork it, if you are the only one that needs what you implement. Otherwise, you first make sure that the feature you implement is in sync with where the piece of software is going overall.


thinking out loud.. if I'm looking at queries for my app, I want to know that it runs the first time properly, and uses cached query for subsequent calls...

Not regarding your UI, I'd envision it in a tree view or some way of drilling down.

Would it be possible to have a timeline view of the executed queries and a relational view (same queries together, possibly different params)?

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats