- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有自己的数据集,我想在 SPARQL 中执行联合查询。这是查询:
PREFIX : <http://myURIsNamespace#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
select * where {
?bioentity :hasMutatedVersionOf ?gene .
?gene :partOf wd:Q430258 .
SERVICE <https://query.wikidata.org/sparql> {
?gene p:P644 ?statement;
wdt:P31 wd:Q7187 ;
wdt:P703 wd:Q15978631 ;
wdt:P1057 wd:Q430258 .
?statement ps:P644 ?start .
?statement pq:P659 wd:Q20966585 .
?gene p:P645 ?statement2.
?statement2 ps:P645 ?end .
?statement2 pq:P659 wd:Q20966585 .
FILTER (xsd:integer(?start)>21000000 && xsd:integer(?start)<30000000)
}
}
我通过 graphDB SPARQL 接口(interface)运行查询,但它真的很慢。返回 8 条记录需要一分钟多的时间。如果我将查询分成两部分,它们的速度非常快。
查询#1
select * where {
?bioentity :hasMutatedVersionOf ?gene .
?gene :partOf wd:Q430258 .
}
0.1s 内 56 条记录
查询#2
select * where {
SERVICE <https://query.wikidata.org/sparql> {
?gene p:P644 ?statement;
wdt:P31 wd:Q7187 ;
wdt:P703 wd:Q15978631 ;
wdt:P1057 wd:Q430258 .
?statement ps:P644 ?start .
?statement pq:P659 wd:Q20966585 .
?gene p:P645 ?statement2.
?statement2 ps:P645 ?end .
?statement2 pq:P659 wd:Q20966585 .
FILTER (xsd:integer(?start)>21000000 && xsd:integer(?start)<30000000)
}
}
0.5s 内 158 条记录
为什么联邦这么慢?有没有办法优化性能?
最佳答案
只需将您的 SERVICE
第一部分,我。 e.之前 ?bioentity :hasMutatedVersionOf ?gene .
上述文章的相关引用:
3.3.2 Query Optimization and Execution
The execution order of query operators significantly influences the overall query evaluation cost.Besides the important query execution time there are also otheraspects in the federated scenario which are relevant for the queryoptimization:
Minimizing communication cost. The number of contacteddata sources directly influences the performance of the queryexecution due to the communication overhead. However, reducing thenumber of involved data source trades off against completeness ofresults.
Optimizing execution localization. The standard queryinterfaces of linked data sources are generally only capable ofanswering queries on their provided data. Therefore, joins withother data results usually need to be done at the query issuer. Ifpossible at all, a better strategy will move parts of the resultmerging operations to the data sources, especially if they can beexecuted in parallel.
Streaming results. Retrieving a complete resultwhen evaluating a query on a large dataset may take a while even witha well optimized execution strategy. Thus one can return results assoon as they become available, which can be optimized by trying toreturn relevant results first.
示例数据
PREFIX : <http://myURIsNamespace#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
INSERT { ?gene rdf:type owl:Thing }
WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?gene p:P644 ?statement;
wdt:P31 wd:Q7187 ;
wdt:P703 wd:Q15978631 ;
wdt:P1057 wd:Q430258 .
?statement ps:P644 ?start .
?statement pq:P659 wd:Q20966585 .
?gene p:P645 ?statement2.
?statement2 ps:P645 ?end .
?statement2 pq:P659 wd:Q20966585 .
FILTER (xsd:integer(?start)>26000000 && xsd:integer(?start)<30000000)
}
}
三元组总数为 79。请注意 26000000
用于代替 21000000
.
查询 1
PREFIX : <http://myURIsNamespace#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT * WHERE {
?gene rdf:type owl:Thing .
SERVICE <https://query.wikidata.org/sparql> {
?gene p:P644 ?statement;
wdt:P31 wd:Q7187 ;
wdt:P703 wd:Q15978631 ;
wdt:P1057 wd:Q430258 .
?statement ps:P644 ?start .
?statement pq:P659 wd:Q20966585 .
?gene p:P645 ?statement2.
?statement2 ps:P645 ?end .
?statement2 pq:P659 wd:Q20966585 .
FILTER (xsd:integer(?start)>20000000 && xsd:integer(?start)<30000000)
}
}
查询 2
PREFIX : <http://myURIsNamespace#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT * WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?gene p:P644 ?statement;
wdt:P31 wd:Q7187 ;
wdt:P703 wd:Q15978631 ;
wdt:P1057 wd:Q430258 .
?statement ps:P644 ?start .
?statement pq:P659 wd:Q20966585 .
?gene p:P645 ?statement2.
?statement2 ps:P645 ?end .
?statement2 pq:P659 wd:Q20966585 .
FILTER (xsd:integer(?start)>20000000 && xsd:integer(?start)<30000000)
}
?gene rdf:type owl:Thing
}
性能
查询1 | 查询2 | |
---|---|---|
图形数据库 | 30 秒 | 1 秒 |
闪耀图 | 1 秒 | 1 秒 |
GraphDB 行为
执行查询 1,GraphDB 执行 79 个不同的 GET
对 Wikidata 的请求¹:
这些请求属于此类查询:
SELECT ?start ?statement ?end ?statement2 WHERE {
<http://www.wikidata.org/entity/Q18031286> p:P644 ?statement;
wdt:P31 wd:Q7187 ;
wdt:P703 wd:Q15978631 ;
wdt:P1057 wd:Q430258 .
?statement ps:P644 ?start .
?statement pq:P659 wd:Q20966585 .
<http://www.wikidata.org/entity/Q18031286> p:P645 ?statement2.
?statement2 ps:P645 ?end .
?statement2 pq:P659 wd:Q20966585 .
FILTER (xsd:integer(?start)>20000000 && xsd:integer(?start)<30000000)
有趣的是,GraphDB 在另一台机器上执行 GET
另一种请求:
GET /sparql?queryLn="Sparql"&query=<original_query_service_part>&$gene=<http://www.wikidata.org/entity/Q18031286>
在此请求中,Sesame protocol使用,URL 中的这些绑定(bind)不是 SPARQL 1.1 Protocol 的一部分.
也许确切的请求类型取决于内部 reuse.vars.in.subselects
的值。参数,默认值在 Windows 和 Linux 上可能不同。
Blazegraph 行为
执行查询 1,Blazegraph 执行单个 POST
对 Wikidata² 的请求:
SELECT ?gene ?statement ?start ?statement2 ?end
WHERE {
?gene p:P644 ?statement;
wdt:P31 wd:Q7187 ;
wdt:P703 wd:Q15978631 ;
wdt:P1057 wd:Q430258 .
?statement ps:P644 ?start .
?statement pq:P659 wd:Q20966585 .
?gene p:P645 ?statement2.
?statement2 ps:P645 ?end .
?statement2 pq:P659 wd:Q20966585 .
FILTER (xsd:integer(?start)>20000000 && xsd:integer(?start)<30000000)
}
VALUES ( ?gene) {
( wd:Q14908148 ) ( wd:Q15320063 ) ( wd:Q17861651 ) ( wd:Q17917753 ) ( wd:Q17928333 )
( wd:Q18024923 ) ( wd:Q18026347 ) ( wd:Q18030710 ) ( wd:Q18031220 ) ( wd:Q18031457 )
( wd:Q18031551 ) ( wd:Q18031832 ) ( wd:Q18032918 ) ( wd:Q18033094 ) ( wd:Q18033798 )
( wd:Q18034311 ) ( wd:Q18035006 ) ( wd:Q18035085 ) ( wd:Q18035609 ) ( wd:Q18036516 )
( wd:Q18036676 ) ( wd:Q18037580 ) ( wd:Q18038385 ) ( wd:Q18038459 ) ( wd:Q18038737 )
( wd:Q18038763 ) ( wd:Q18039997 ) ( wd:Q18040291 ) ( wd:Q18041261 ) ( wd:Q18041415 )
( wd:Q18041558 ) ( wd:Q18045881 ) ( wd:Q18047232 ) ( wd:Q18047373 ) ( wd:Q18047918 )
( wd:Q18047966 ) ( wd:Q18048744 ) ( wd:Q18049145 ) ( wd:Q18049164 ) ( wd:Q18053139 )
( wd:Q18056540 ) ( wd:Q18057411 ) ( wd:Q18060804 ) ( wd:Q18060856 ) ( wd:Q18060876 )
( wd:Q18060905 ) ( wd:Q18060958 ) ( wd:Q20773708 ) ( wd:Q15312971 ) ( wd:Q17860819 )
( wd:Q17917713 ) ( wd:Q18026310 ) ( wd:Q18027015 ) ( wd:Q18031286 ) ( wd:Q18032599 )
( wd:Q18032797 ) ( wd:Q18035169 ) ( wd:Q18035627 ) ( wd:Q18039938 ) ( wd:Q18041207 )
( wd:Q18041512 ) ( wd:Q18041930 ) ( wd:Q18045491 ) ( wd:Q18045762 ) ( wd:Q18046301 )
( wd:Q18046472 ) ( wd:Q18046487 ) ( wd:Q18047149 ) ( wd:Q18047491 ) ( wd:Q18047719 )
( wd:Q18048527 ) ( wd:Q18049774 ) ( wd:Q18051886 ) ( wd:Q18053875 ) ( wd:Q18056212 )
( wd:Q18056538 ) ( wd:Q18065866 ) ( wd:Q20766978 ) ( wd:Q20781543 )
}
结论
使用联合查询,很难创建有效的执行计划,因为远程模式的选择性是未知的。
在您的特定情况下,是否在本地或远程加入结果应该不是很重要,因为本地和远程结果集都很小。但是,在 GraphDB 中,远程加入结果的效果较差,因为 GraphDB 不会降低通信成本。
¹ 对于创建屏幕截图,<http://query.wikidata.org/sparql>
而不是 <https://query.wikidata.org/sparql>
被使用了。
² 在 Blazegraph 中,可以写成 hint:Query hint:optimizer "None"
以确保顺序评估。
关于query-optimization - SPARQL 加速联合查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45356326/
我正在尝试运行以下代码片段,以使曲线适合一些经验数据,但在Julia Optim.jl包中,optimize()方法一直存在问题。我正在使用Julia v1.1.0,并安装了所有正确的软件包。我不断收
时不时你会听到一些故事,这些故事旨在说明某人在某件事上有多擅长,有时你会听到这个人如何热衷于代码优化,以至于他优化了他的延迟循环。 因为这听起来确实是一件奇怪的事情,因为启动“计时器中断”而不是优化的
我正在尝试使用 z3py 作为优化求解器来最大化从一张纸上切出的长方体的体积。 python API 提供了 Optimize() 对象,但使用它似乎不可靠,给我的解决方案显然不准确。 我尝试使用 h
我今天接受了采访。这个问题是为了优化下面的代码。如果我们将在 for 循环之后看到下面的代码,那么下面有四个“if-else”步骤。所以,面试官要求我将其优化为 3 if-else 行。我已经尝试了很
我使用BFGS算法使用Optim.jl库来最小化Julia中的函数。今天,我问了一个关于同一个库的question,但是为了避免混淆,我决定将它分成两部分。 我还想对优化后的负逆黑森州进行估算,以进行
在 haskell 平台中实现许多功能时有一个非常常见的模式让我很困扰,但我找不到解释。这是关于使用嵌套函数进行优化。 where 子句中的嵌套函数旨在进行尾递归的原因对我来说非常清楚(如 lengt
我目前正试图利用 Julia 中的 Optim 包来最小化成本函数。成本函数是 L2 正则化逻辑回归的成本函数。其构造如下; using Optim function regularised_cost
我正在使用 GEKKO 来解决非线性规划问题。我的目标是将 GEKKO 性能与替代方案进行比较,因此我想确保我从 GEKKO 中获得其所能提供的最佳性能。 有n个二元变量,每个变量都分配有一个权
我可以手动更改参数C和epsilon以获得优化结果,但我发现有PSO(或任何其他优化算法)对SVM进行参数优化。没有算法。什么意思:PSO如何自动优化SVM参数?我读了几篇关于这个主题的论文,但我仍然
我正在使用 scipy.optimize.fmin_l_bfgs_b 来解决高斯混合问题。混合分布的均值通过回归建模,其权重必须使用 EM 算法进行优化。 sigma_sp_new, func_val
当你有一个 Option ,编译器知道 NULL永远不是 &T 的可能值, 和 encodes the None variant as NULL instead .这样可以节省空间: use std:
当你有一个 Option ,编译器知道 NULL永远不是 &T 的可能值, 和 encodes the None variant as NULL instead .这样可以节省空间: use std:
以下是说明我的问题的独立示例。 using Optim χI = 3 ψI = 0.5 ϕI(z) = z^-ψI λ = 1.0532733 V0 = 0.8522423425 zE = 0.598
根据MySQL文档关于Optimizing Queries With Explain : * ALL: A full table scan is done for each combination o
我无法预览我的 Google 优化工具体验。 Google 优化抛出以下错误: 最佳答案 我也经常遇到这种情况。 Google 给出的建议是错误的。清除 cookie 并重新启动浏览器并不能解决问题。
我一直在尝试使用 optim()或 optimize()函数来最小化绝对预测误差的总和。 我有 2 个向量,每个长度为 28,1 个包含预测数据,另一个包含过去 28 天的实际数据。 fcst和 ac
在我对各种编译器书籍和网站的独立研究中,我了解到编译器可以优化正在编译的代码的许多不同方法,但我很难弄清楚每种优化会带来多少好处给予。 大多数编译器编写者如何决定首先实现哪些优化?或者哪些优化值得付出
我在我的项目中使用 System.Web.Optimizations BundleConfig。我在我的网站上使用的特定 jQuery 插件遇到了问题。如果我将文件添加到我的 ScriptBundle
我收到这个错误 Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.
scipy的optimize.fmin和optimize.leastsq有什么区别?它们似乎在 this example page 中以几乎相同的方式使用.我能看到的唯一区别是 leastsq 实际上
我是一名优秀的程序员,十分优秀!