jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcel Reutegger <marcel.reuteg...@gmx.net>
Subject Re: [jira] Resolved: (JCR-651) Improve performance for queries with large result sets
Date Tue, 05 Dec 2006 10:21:49 GMT
wendy Lee wrote:
> If I use this config & set resultFetchSize to 50 , When I use  "count =
> result.getNodes().getSize()" the count is 50?or the total amount in the
> query condition?

It's approximately the total amount. If the session has access to all result 
nodes the size information is correct. If the session is not allowed to see 
certain nodes the result set the size my change while iterating over the result 


resultFetchSize is set to 2

If a superuser would execute query Q she would see result nodes N1, N2, N3, N4 
and N5. NodeIterator.getSize() will always return 5.

If a user is not allowed to see N2 and N4 and executes query Q he will encounter 
the following behaviour:

NodeIterator it = result.getNodes();
it.getSize(); // = 4, because the query has a raw result size of 5
               //      but found out while fetching 2 nodes in the result
               //      iterator that the session does not have access to N2
it.nextNode(); // returns N1
it.nextNode(); // returns N3
it.getSize(); // = 3, because 2 nodes have been consumed more result nodes
               //      are fetched. This time the result will try to fetch twice
               //      as many nodes as before. That's 4. N4 is not visible to
               //      the session, but N5 is. Therefore the size is decreased
               //      to 3.
it.nextNode() // returns N5
it.nextNode() // throws NoSuchElementException

This means, depending on the configuration you cannot depend on getSize() being 
100% correct. But that was also the case before, because while you iterate over 
the result nodes one of them might get deleted in the meantime.

If you need a more accurate size you can simply increase the configuration 
parameter 'resultFetchSize'.

Please note that the following loop will never throw a NoSuchElementException 
even though the getSize() may change over time (because result nodes might have 
been deleted in the meantime, or the session does not have access to it):

for (NodeIterator it = result.getNodes(); it.hasNext(); ) {


View raw message