sparql - 使用 UNION 和 FILTER 的慢速 BlazeGraph SPARQL 查询
问题描述
我正在针对Wikidata 查询服务对Blazegraph RDF Graph 数据库进行 SPARQL 查询。这些查询涉及几个 UNION,通常是一个 FILTER
SELECT DISTINCT ?music_track ?music_trackLabel ?artist ?artistLabel ?album ?albumLabel ?publication_date WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
{ ?music_track wdt:P31 wd:Q134556. }
UNION
{ ?music_track wdt:P31 wd:Q7366. }
UNION
{ ?music_track wdt:P31 wd:Q2188189. }
UNION
{ ?music_track wdt:P31 wd:Q207628. }
UNION
{ ?music_track wdt:P31 wd:Q7302866. }
UNION
{ ?music_track wdt:P31 wd:Q9748. }
UNION
{ ?music_track wdt:P2207 ?_spotifyTrackID_. }
?music_track rdfs:label ?music_trackLabel.
?music_track wdt:P175 ?artist.
?artist rdfs:label ?artistLabel.
OPTIONAL { ?music_track wdt:P361 ?album.}
OPTIONAL { ?music_track wdt:P577 ?publication_date. }
FILTER regex(?music_trackLabel, "^Castle on the Hill$", "i")
FILTER (regex(?artistLabel, "ed sheeran", "i"))
}
LIMIT 10
或喜欢
SELECT DISTINCT ?artist ?artistLabel ?birth_nameLabel ?date ?website ?instagramID ?facebookID ?twitterID ?musicBrainzArtistID WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
{ ?artist wdt:P31 wd:Q215380. }
UNION
{ ?artist wdt:P31 wd:Q2088357. }
UNION
{ ?artist wdt:P31 wd:Q5741069. }
UNION
{ ?artist wdt:P31 wd:Q641066. }
UNION
{ ?artist wdt:P1902 ?_spotifyArtistID_. }
UNION
{ ?artist wdt:P2850 ?_itunesArtistID_. }
UNION
{ ?artist wdt:P434 ?musicBrainzArtistID. }
FILTER(REGEX(?artistLabel, "^Fall Out Boy$", "i"))
?artist rdfs:label ?artistLabel.
OPTIONAL { ?artist wdt:P571 ?date. }
OPTIONAL { ?artist wdt:P1477 ?birth_nameLabel. }
OPTIONAL { ?artist wdt:P856 ?website. }
OPTIONAL { ?artist wdt:P2003 ?instagramID. }
OPTIONAL { ?artist wdt:P2013 ?facebookID. }
OPTIONAL { ?artist wdt:P2002 ?twitterID. }
}
LIMIT 10
这些查询非常慢(从几秒到十多秒不等),我想优化这些查询。
使用 Blazegraph 仪表板,我做了一个查询 EXPLAIN,但我不了解如何优化以及优化什么。
解决方案
推荐阅读
- next.js - 在 Next.js 中放置 Router.events 相关代码的位置
- sql-server - 在 SQL Server 与 Excel 中将 int 转换为日期
- node.js - 为不同的 VS 解决方案使用特定版本的 npm/node?
- python-3.x - 比较多个条件时如何仅获得一个布尔值?
- mysql - 如何根据和条件获取数据
- python - 不想在 listWidget 中点击/突出显示图标
- c# - 如何使用 csvhelper 高效地编写包含数千列的 csv 文件?
- .net - Visual Studio 2017 不显示已编辑/添加的图标
- react-native - 底部导航 | 反应原生
- java - 只绘制应该在屏幕上的节点?