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.  [ 5 posts ] 
Author Message
 Post subject: Query Cache does not respect Batch-Size
PostPosted: Sat Feb 09, 2008 5:40 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
Let me start by saying that I understand that the query cache is meant to work in conjunction with the entity cache, in that the query cache only caches IDs, which should then hopefully retrieve the corresponding entities from the entity cache rather than hitting the database. Every entity cache miss results in a SQL statement being executed to load the entity. Obviously this could lead to a lot of SQL being executed due to query caching.

What I want to ask about it is: why doesn't the query cache use the same batch-initialization mechanism that our proxies do? Is this a design decision, an accidental omission, or a future feature?

If you like I can post my code, but my tests appear to show that if I set batch-size=3 for my User class, then load 8 instances by their IDs, then loop through printing out the username, I do indeed see 3 batches of SQL queries.

However, if I load those same 8 users with a cached CreateQuery("from User") or CreateCriteria(typeof(User)), the original query is indeed cached, but for initializing the entities, neither of those operations uses batch-size and instead issues 8 SELECT statements.

Also it appears that with entity caching enabled, the cached HQL IQuery puts the entities into the cache the first time it is listed, but the cached Criteria query does not. With ICriteria I had to do 3 runs to get full caching whereas with IQuery I only had to do 2.
* The first loaded all the entities but appears not to have cached them
* The second was able to get the cached IDs, but had to load the entities (and didn't batch them)
* On the third run, both the query results and the IDs were in the cache


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 1:33 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
I think I've figured this out. I'm still curious whether this is by design or if I should submit it to JIRA (btw -- is JIRA down?).

The reason that neither ICriteria nor IQuery support batched initalization of cached queries is that they both use the default version of ManyToOneType as the returnType for an entity, as does NHibernateUtils.Entity. The problem is that ManyToOneType, by default, sets its "eager" field to true. So, when Assemble() calls ResolveIdentifier, it tells the loader not to allow proxies. I flipped "eager" to false and it returned proxies, which then allowed batch loading.

Unfortunately I don't see any non-invasive way to do this, so I guess I'd have to modify the NH source in the two places where IQuery and ICriteria construct their ManyToOneType(s).

Anyone have any thoughts on this?

Also, I resolved the problem I mentioned in italics. It was my fault -- my test case Setup() was evicting items from the SessionFactory but not the from Session itself.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 12:11 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
Just confirmed that cached collections behave the same way - they don't batch load when retrieved from the collection cache.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 1:33 pm 
Regular
Regular

Joined: Tue Dec 25, 2007 3:41 pm
Posts: 57
Location: Argentina
For the moment, the Jira is here:
http://www.covalentsw.com:8080/secure/Dashboard.jspa

_________________
Dario Quintana


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 02, 2008 5:14 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
Thanks. I logged an issue and also posted a patch that appears to fix the problem.

http://www.covalentsw.com:8080/browse/NH-1247


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