I need to provide isolation between similar triples in different graphs (collections) in MarkLogic. For this to work I have to specify which graph I want the triples to be retrieved from, and my approach is this:
cts:triples(
(),
sem:iri("http://something/predicate#somepredicate"), "SomeObject", (), (),
cts:collection-query("someCollection") )
This works, but it performs poorly because of the collection-query. Are there any better ways to limit results to only these of a given graph?
I tried to create a test case for this, using 7.0-4 on my laptop. It seems pretty fast to me: take a look and see where it's different from what you're doing. My guess is that your query returns many triples, and that's the bottleneck. Matching triples is very fast, but returning large numbers of them can be relatively slow.
First let's use taskbot to generate some triples.
Now, taskbot does most of the work on the Task Server. So monitor
ErrorLog.txt
or just wait for the CPU to go down and the triple count to hit 1M. After that, let's see what we loaded:You might get a different counts for the predicate, object, and collection: remember that the data was generated randomly. But let's try a query.
Results:
That seems pretty fast to me: 5-ms. You might get a different count because the data was generated randomly, but it should be close.
Now, a larger result set will slow this down. For example:
As you can see, the response time is roughly O(n) with the number of triples. Actually it's a little better than O(n), but in that ballpark. In any case the
cts:collection-query
doesn't look like the problem.