Hi Christian,
as you have already seen, all results are first cached by the client if they are requested via the iterative query protocol. In earlier versions of BaseX, results were returned in a purely iterative manner -- which was more convenient and flexible from a user's point of view, but led to numerous deadlocks if reading and writing queries were mixed.
If you only need parts of the requested results, I would recommend to limit the number of results via XQuery, e.g. as follows:
( for $i in /record[@version = > 0] order by $i/system/index return $i) [position() = 1 to 1000]
I had considered this, but haven't used that approach - yet - mainly because I wanted to try the streaming approach first. So far our system only used MongoDB and we are used to working with cursors as query results, so I'm trying to keep that somehow aligned if possible.
Next, it is important to note that the "order by" clause can get very expensive, as all results have to be cached anyway before they can be returned. Our top-k functions will probably give you better results if it's possible in your use case to limit the number of results [1].
Ok, thanks. If this becomes a problem, I'll consider using this. Is the query time of 0.06ms otherwise the actual time the query takes to run? If yes then I'm not too worried about query performance :) In general, the bottleneck in our system is not so much the querying but rather the processing of the records - I started rewriting this one concurrently using Akka, but am now stuck with a classloader deadlock (no pun intended). It will likely take quite some effort for the processing to be faster than the query iteration.
A popular alternative to client-side caching (well, you mentioned that already) is to overwrite the code of the query client, and directly process the returned results. Note, however, that you need to loop through all results, even if you only need parts of the results.
I implemented this and it looks like it works nicely (to be confirmed soon - I started a run on a 600k records collection).
Thanks for your time!
Manuel
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Higher-Order_Functions_Module#hof:top-k-by