Is there a way to optimize SPARQL queries?

I have unmanaged triples stored as part of separate documents that I keep in my db content. In fact, each document represents a person, and a particular tee indicates the document URI for the character manager. I am trying to use SPARQL to determine the length of paths between a manager and all the people below them in a hierarchy.

The triples in the document look like

<sem:triple xmlns:sem="http://marklogic.com/semantics"> <sem:subject>http://rdf.abbvienet.com/infrastructure/person/10740024</sem:subject> <sem:predicate>http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager</sem:predicate> <sem:object>http://rdf.abbvienet.com/infrastructure/person/10206242</sem:object> </sem:triple> 

I found the following sparql query, which can be used to return a manager, aperson below them in the hierarchy and the number of remote nodes.

 select ?manager ?leaf (count(?mid) as ?distance) { BIND(<http://rdf.abbvienet.com/infrastructure/person/10025613> as ?manager) ?leaf <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>* ?mid . ?mid <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>+ ?manager . } group by ?manager ?leaf order by ?manager ?leaf 

This works, but very slowly, even when the hierarchy tree I'm looking at is one or two levels deep, about 15 seconds. I have 63,139 control triples of this type in db.

+5
source share
1 answer

I think the biggest problem will be BIND() - MarkLogic 8 does not optimize the template that you use generally well. Can you try replacing your constant with the places where you use the variable ?manager to see if this value matters a lot? i.e:.

 select ?leaf (count(?mid) as ?distance) { ?leaf <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>* ?mid . ?mid <http://schemas.abbvienet.com/ontologies/infrastructure.owl#manager>+ <http://rdf.abbvienet.com/infrastructure/person/10025613> . } group by ?leaf order by ?leaf 

StackOverflow is not a great place to answer such productivity questions, as it does require a conversation where we work together to help you. Perhaps you can try contacting support or the MarkLogic developer mailing list for these kinds of questions?

+6
source

All Articles