SPARQL查询中表达式的顺序
下面两个查询之间有什么区别吗SPARQL查询中表达式的顺序,sparql,rdf,semantic-web,rdfs,triplestore,Sparql,Rdf,Semantic Web,Rdfs,Triplestore,下面两个查询之间有什么区别吗 select distinct ?i where{ ?i rdf:type <http://foo/bar#A>. FILTER EXISTS { ?i <http://foo/bar#hasB> ?b. ?b rdf:type <http://foo/bar#B1>. } } select distinct ?i where{
select distinct ?i
where{
?i rdf:type <http://foo/bar#A>.
FILTER EXISTS {
?i <http://foo/bar#hasB> ?b.
?b rdf:type <http://foo/bar#B1>.
}
}
select distinct ?i
where{
FILTER EXISTS {
?i <http://foo/bar#hasB> ?b.
?b rdf:type <http://foo/bar#B1>.
}
?i rdf:type <http://foo/bar#A>.
}
选择distinct?i
在哪里{
?i rdf:类型。
过滤器存在{
i?b。
?b rdf:类型。
}
}
选择distinct?i
在哪里{
过滤器存在{
i?b。
?b rdf:类型。
}
?i rdf:类型。
}
在性能或结果方面存在差异?首先,您不需要
过滤器存在
。您可以使用基本图形模式(一组规则的三重模式)重写查询。但是假设您正在使用过滤器notexists
或类似的东西
后果
一般来说
然而,自上而下的求值语义主要在可选的情况下发挥作用,而这不是您的情况。因此,结果应该是相同的
自顶向下的计算语义可以被计算语义覆盖。幸运的是,自底向上的语义首先在逻辑上评估过滤器
,尽管在过滤器存在
和过滤器不存在
的情况下是可能的
SPARQL代数对于两个查询都是相同的:
(prefix ((rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
(foobar: <http://foo/bar#>))
(distinct
(project (?i)
(filter (exists
(bgp
(triple ?i foobar:B ?b)
(triple ?b rdf:type foobar:B1)
))
(bgp (triple ?i rdf:type foobar:A))))))
(前缀((rdf:)
(福巴:)
(明显的
(项目(?i)
(过滤器(存在)
(bgp
(三重i foobar:B?B)
(三重b rdf:foobar:B1型)
))
(bgp(三重i rdf:type foobar:A()()())))
表演
简单地遵循自上而下的语义,引擎应该首先计算?i a foobar:a
- 如果
?i
只存在一个绑定,那么您是幸运的
- 如果存在数以百万计的
?i
绑定,而子模式更具选择性,那么您就没那么幸运了
幸运的是,优化器试图根据模式的选择性对其重新排序。然而,预测可能是错误的
顺便说一句,rdf:type
断言了Virtuoso中的性能杀手
结果与绩效
如果端点有查询执行时间限制,并在达到超时时刷新部分结果,则结果可能不同:。否,结果没有差异,它只是?i
绑定上的一个过滤器