sparql - 在查询中使用 VALUES 关键字和直接使用 URI 之间的性能差异?
问题描述
我有一个相当复杂的 SPARQL 查询,其结构如下所述,涉及多个图形模式,UNION
并且嵌套了FILTER NOT EXISTS
.
我希望查询保持通用,并且我希望能够在执行时为某些变量注入值,我的想法是VALUES
在查询末尾附加一个关键字来指定查询中某些变量的值。在下面的结构中,我设置了 的值?x
,并说明了查询中?x
适用的所有位置。
但是,在 Fuseki 中,我看到执行这样的查询大约需要 4 到 5 秒,但是用?x
URI 手动替换查询中的变量,而不是指定VALUES
子句,使它运行得非常快。
- 我一直认为
VALUES
在子句末尾使用关键字WHERE
就像为某些变量内联设置值,所以我希望使用VALUES
子句或将变量替换为相应的 URI 在查询执行方面是相同的。VALUES
有人可以确认关键字的预期行为吗?WHERE
还要解释在子句外使用它还是在子句内使用它的区别WHERE
? VALUES
变量集 using出现在FILTER NOT EXISTS
子句中的事实是否改变了某些东西?- 您能否确认这是满足上述要求的正确方法(我希望查询保持通用,并且我希望能够在执行时为某些变量注入值)?
- 这种行为是否可能特定于 Fuseki 的处理方式
VALUES
?
谢谢 !
SELECT DISTINCT ...
WHERE {
# ?x ...
# ... basic graph pattern here
{
{
# ... basic graph pattern here
FILTER NOT EXISTS {
# ?x ...
# ... basic graph pattern here
}
FILTER NOT EXISTS {
# ... basic graph pattern here
FILTER NOT EXISTS {
# ?x ...
# ... basic graph pattern here
}
}
}
UNION
{
?x ...
# ... basic graph pattern here
}
UNION
{
# ... basic graph pattern here
FILTER NOT EXISTS {
?x ...
# ... basic graph pattern here
}
FILTER NOT EXISTS {
# ... basic graph pattern here
FILTER NOT EXISTS {
?x ...
# ... basic graph pattern here
}
}
}
UNION
{
?x ...
}
}
}
VALUES ?x { <http://example.com/Foo> }
解决方案
不应该是一个答案,但在评论中格式化是不可能的......
代数树至少有一些明显的区别。如何处理这可能是特定于实现的。安迪比我更了解,希望能给出更有用的答案。
没有VALUES
:
询问
SELECT ?s ?o
WHERE
{ { <test_val> <p> ?o }
UNION
{ <test_val> <p> ?o
FILTER NOT EXISTS { <test_val> a ?type }
}
}
代数树(优化)
(base <http://example/base/>
(project (?s ?o)
(union
(bgp (triple <test_val> <p> ?o))
(filter (notexists (bgp (triple <test_val> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type)))
(bgp (triple <test_val> <p> ?o))))))
和VALUES
询问
SELECT ?s ?o
WHERE
{ { ?s <p> ?o }
UNION
{ ?s <p> ?o
FILTER NOT EXISTS { ?s a ?type }
}
}
VALUES ?s { <test_val> }
代数树
(base <http://example/base/>
(project (?s ?o)
(join
(union
(bgp (triple ?s <p> ?o))
(filter (notexists (bgp (triple ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type)))
(bgp (triple ?s <p> ?o))))
(table (vars ?s)
(row [?s <test_val>])
))))
代数树(优化)
(base <http://example/base/>
(project (?s ?o)
(sequence
(table (vars ?s)
(row [?s <test_val>])
)
(union
(bgp (triple ?s <p> ?o))
(filter (notexists (bgp (triple ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type)))
(bgp (triple ?s <p> ?o)))))))
推荐阅读
- python - “错误:由于 EnvironmentError 无法安装软件包:[Errno 28] 设备上没有剩余空间”,即使我还有 100 GB 以上的空间
- mql4 - mql4 将对象保存到数组然后保存到文件
- c++ - 我重载了 << 和 = 运算符。为什么当我将一个对象分配给另一个对象并尝试打印它时,我会打印出垃圾?
- javascript - D3JS 如何将数据发送到事件中
- objective-c - 推送通知在前台 IOS 中不起作用
- json - 使用角度将json对象写入资产中的file.json
- r - 包“get_ontology”不可用(对于 R 版本 3.6.3)
- android - 如何在单击按钮时使用“意图”启动 Facebook lite
- oracle - 获取时游标无效
- amazon-cloudformation - CodePipeline 失败并显示“操作失败,因为找不到工件或 Amazon S3 存储桶。”