有没有办法优化SPARQL查询?

TJ *_*ang 5 sparql marklogic marklogic-8

我将非托管三元组存储为我存储在内容数据库中的单个文档的一部分.基本上每个文档代表一个人,定义的三元组指定了该人的经理的文档URI.我正在尝试使用SPARQL来确定管理器与层次结构中它们下面的所有人之间的路径长度.

文档中的三元组看起来像

<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>
Run Code Online (Sandbox Code Playgroud)

我找到了以下sparql查询,该查询可用于返回管理器,层次结构中位于它们下方的人员以及它们所在的节点数量.

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
Run Code Online (Sandbox Code Playgroud)

这是有效的,但是非常慢,即使我正在查看的层次结构树是一个或两个深度,大约15s.我在db中有63,139个这种类型的管理器三元组.

Joh*_*son 6

我认为最大的问题是BIND()- MarkLogic 8并没有优化你正在使用的模式.你可以尝试将你的常数替换为你使用?manager变量的地方,看看它是否会产生很大的不同?即:

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
Run Code Online (Sandbox Code Playgroud)

StackOverflow不是回答这样的性能问题的好地方,因为它真的需要我们一起工作来帮助您的对话.也许你可以尝试联系支持MarkLogic开发人员邮件列表来解决这类问题?